Author: rfm Date: Sat Oct 8 09:02:06 2016 New Revision: 40137 URL: http://svn.gna.org/viewcvs/gnustep?rev=40137&view=rev Log: Check for file modification during copy
Modified: libs/base/trunk/ChangeLog libs/base/trunk/Source/NSFileManager.m Modified: libs/base/trunk/ChangeLog URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=40137&r1=40136&r2=40137&view=diff ============================================================================== --- libs/base/trunk/ChangeLog (original) +++ libs/base/trunk/ChangeLog Sat Oct 8 09:02:06 2016 @@ -1,3 +1,8 @@ +2016-10-05 Richard Frith-Macdonald <r...@gnu.org> + + * Source/NSFileManager.m: Check for modification of source file + during copy. + 2016-10-05 Richard Frith-Macdonald <r...@gnu.org> * Source/Additions/Unicode.m: Permit noncharacter unicode codepoints Modified: libs/base/trunk/Source/NSFileManager.m URL: http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSFileManager.m?rev=40137&r1=40136&r2=40137&view=diff ============================================================================== --- libs/base/trunk/Source/NSFileManager.m (original) +++ libs/base/trunk/Source/NSFileManager.m Sat Oct 8 09:02:06 2016 @@ -2767,6 +2767,7 @@ #else NSDictionary *attributes; + NSDate *modification; unsigned long long fileSize; unsigned long long i; int bufsize = 8096; @@ -2787,6 +2788,7 @@ fileSize = [attributes fileSize]; fileMode = [attributes filePosixPermissions]; + modification = [attributes fileModificationDate]; /* Open the source file. In case of error call the handler. */ sourceFd = open([self fileSystemRepresentationWithPath: source], @@ -2819,8 +2821,12 @@ for (i = 0; i < fileSize; i += rbytes) { rbytes = read (sourceFd, buffer, bufsize); - if (rbytes < 0) - { + if (rbytes <= 0) + { + if (0 == rbytes) + { + break; // End of input file + } close (sourceFd); close (destFd); @@ -2847,6 +2853,18 @@ close (sourceFd); close (destFd); + /* Check for modification during copy. + */ + attributes = [self fileAttributesAtPath: source traverseLink: NO]; + if (NO == [modification isEqual: [attributes fileModificationDate]] + || [attributes fileSize] != fileSize) + { + return [self _proceedAccordingToHandler: handler + forError: @"source modified during copy" + inPath: destination + fromPath: source + toPath: destination]; + } return YES; #endif } _______________________________________________ Gnustep-cvs mailing list Gnustep-cvs@gna.org https://mail.gna.org/listinfo/gnustep-cvs