@@ -353,9 +353,9 @@ public function writeFile() {
353
353
$ fileLines = file ($ file );
354
354
$ contents = $ this ->systemClass ->stitchChanges ($ fileLines , $ _POST ['changes ' ]);
355
355
356
- // get old file contents, and count stats on usage \n and \r there
357
- // in this case we can keep line endings, which file had before, without
358
- // making code version control systems going crazy about line endings change in whole file.
356
+ // Get old file contents, and count stats on usage \n and \r\n
357
+ // We use this info shortly to standardise the file to the same line endings
358
+ // throughout, whichever is greater
359
359
$ oldContents = file_exists ($ file ) ? getData ($ file ) : '' ;
360
360
$ unixNewLines = preg_match_all ('/[^\r][\n]/u ' , $ oldContents );
361
361
$ windowsNewLines = preg_match_all ('/[\r][\n]/u ' , $ oldContents );
@@ -368,11 +368,13 @@ public function writeFile() {
368
368
$ systemClass ->invalidateOPCache ($ file );
369
369
$ fh = fopen ($ file , 'w ' ) or die ($ t ['Sorry, cannot save ' ]);
370
370
371
- // replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
371
+ // Replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
372
372
$ contents = str_replace ("\r\n" , $ ICEcoder ["lineEnding " ], $ contents );
373
373
$ contents = str_replace ("\r" , $ ICEcoder ["lineEnding " ], $ contents );
374
374
$ contents = str_replace ("\n" , $ ICEcoder ["lineEnding " ], $ contents );
375
- if (isset ($ _POST ['changes ' ]) && (0 < $ unixNewLines ) || (0 < $ windowsNewLines )) {
375
+ // Finally, replace the line endings with whatever what greatest in the file before
376
+ // (We do this to help avoid a huge number of unnecessary changes simply on line endings)
377
+ if (isset ($ _POST ['changes ' ]) && (0 < $ unixNewLines || 0 < $ windowsNewLines )) {
376
378
if ($ unixNewLines > $ windowsNewLines ){
377
379
$ contents = str_replace ($ ICEcoder ["lineEnding " ], "\n" , $ contents );
378
380
} elseif ($ windowsNewLines > $ unixNewLines ){
@@ -735,7 +737,7 @@ public function returnJSON() {
735
737
} else {
736
738
$ itemAbsPath = $ file ;
737
739
$ itemPath = dirname ($ file );
738
- $ itemBytes = is_dir ($ file ) ? null : filesize ($ file );
740
+ $ itemBytes = is_dir ($ file ) || ! file_exists ( $ file ) ? null : filesize ($ file );
739
741
$ itemType = (file_exists ($ file ) ? (is_dir ($ file ) ? "dir " : "file " ) : "unknown " );
740
742
$ itemExists = (file_exists ($ file ) ? "true " : "false " );
741
743
}
0 commit comments