Changeset 35267
- Timestamp:
- 10/19/2015 12:52:08 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/misc.php
r34828 r35267 97 97 * @since 1.5.0 98 98 * 99 * @param string $filename100 * @param string $marker101 * @param array $insertion99 * @param string $filename Filename to alter. 100 * @param string $marker The marker to alter. 101 * @param array|string $insertion The new content to insert. 102 102 * @return bool True on write success, false on failure. 103 103 */ 104 104 function insert_with_markers( $filename, $marker, $insertion ) { 105 if ( ! is_writeable( $filename ) ) { 105 if ( ! file_exists( $filename ) ) { 106 if ( ! is_writable( dirname( $filename ) ) ) { 107 return false; 108 } 109 if ( ! touch( $filename ) ) { 110 return false; 111 } 112 } elseif ( ! is_writeable( $filename ) ) { 106 113 return false; 107 114 } 108 115 109 116 if ( ! is_array( $insertion ) ) { 110 $insertion = array($insertion );117 $insertion = explode( "\n", $insertion ); 111 118 } 112 119 … … 128 135 129 136 // Split out the existing file into the preceeding lines, and those that appear after the marker 130 $pre_lines = $post_lines = array();137 $pre_lines = $post_lines = $existing_lines = array(); 131 138 $found_marker = $found_end_marker = false; 132 139 foreach ( $lines as $line ) { … … 142 149 } elseif ( $found_marker && $found_end_marker ) { 143 150 $post_lines[] = $line; 144 } 151 } else { 152 $existing_lines[] = $line; 153 } 154 } 155 156 // Check to see if there was a change 157 if ( $existing_lines === $insertion ) { 158 flock( $fp, LOCK_UN ); 159 fclose( $fp ); 160 161 return true; 145 162 } 146 163 … … 158 175 $bytes = fwrite( $fp, $new_file_data ); 159 176 if ( $bytes ) { 160 ftruncate( $fp, $bytes);161 } 162 177 ftruncate( $fp, ftell( $fp ) ); 178 } 179 fflush( $fp ); 163 180 flock( $fp, LOCK_UN ); 164 181 fclose( $fp );
Note: See TracChangeset
for help on using the changeset viewer.