سؤال

I use NSFileManager setAttribute to set the modification date for files.

Everything works fine but when I do that on some SMB disks sometimes in a non deterministic manner the date isn't changed.

The code shown below for simplicity doesn't check error but in real code all API calls return success so it's impossible to understand what hell doesn't work

What I do is

  • copy files (and subdirectories) from a source folder to a destination folder
  • destination folder is a SMB disk
  • after a copy I set the modification date for copied file (I change modification date only for files I don't take care of directories)
  • some files are correctly updated but some files don't (not always the same)!!!!!!
  • different smb disks have different results (eg winxp mount, buffalo)
  • my code runs inside a separated thread

The code I use is

NSString* srcPath = @"/Volumes/smbtest/folder-1/ATKXP.INF";
NSString* destPath = @"/Volumes/smbtest/folder-2/ATKXP.INF";


NSDictionary* srcAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:srcPath
                                                                          error:nil];
[[NSFileManager defaultManager] copyItemAtPath:srcPath
                                        toPath:destPath
                                         error:nil];

NSDictionary* dateAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
                           srcAttrs.fileCreationDate, NSFileCreationDate,
                           srcAttrs.fileModificationDate, NSFileModificationDate,
                           nil];

[[NSFileManager defaultManager] setAttributes:dateAttrs
                                 ofItemAtPath:destPath
                                        error:nil];

Everything work always correctly on local HFS disks

هل كانت مفيدة؟

المحلول

Doesn't look like there's an error. So the problem seems like it's in either the file system driver or on the server side. I don't know if you're in a position to look at logs on the server. In any case, it seems like it's beyond your control. Either live with the behavior or try putting a check for the attribute value after trying to set it and, if it isn't what you tried to set it to, try again (up to some retry limit).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top