mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Check for file modification during copy
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@40137 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0fe344d12a
commit
28de617ef6
2 changed files with 24 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
2016-10-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSFileManager.m: Check for modification of source file
|
||||
during copy.
|
||||
|
||||
2016-10-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/Unicode.m: Permit noncharacter unicode codepoints
|
||||
|
|
|
@ -2767,6 +2767,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
|
||||
#else
|
||||
NSDictionary *attributes;
|
||||
NSDate *modification;
|
||||
unsigned long long fileSize;
|
||||
unsigned long long i;
|
||||
int bufsize = 8096;
|
||||
|
@ -2787,6 +2788,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
|
||||
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 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
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 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue