Closed damiarnold closed 6 years ago
In looking through the code base some more, it appears that the following logic is in a number of functions when calling File.CreateFileCore()
:
isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.ReadOnly
Same reasoning as listed above may apply to some of these other cases as well....
Thanks for the patch offer; I've decided to do it myself as a chance to get back "into" the AlphaFS code.
No worries! I'll be watching for updates and test when ready.
Looks like the update is working for my case. Thanks!
In the function
SetFsoDateTimeCore()
, there is a conditional set of flags/attributes for the underlyingCreateFile()
native function call.The initial flags/attributes set for the call is determined by this line in the function:
var attributes = isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.ReadOnly;
This is problematic for a couple of reasons:
This function calls
CreateFileCore()
withFileMode.Open
(value of '3') which corresponds to CreateFile's dwCreationDisposition ofOPEN_EXISTING
. According to documentation (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa363874(v=vs.85).aspx) all FILEATTRIBUTE values passed to CreateFile's dwFlagsAndAttributes parameter are ignored when opening existing files and only FILEFLAG values are honored. For this reason, the use of theExtendedFileAttributes.ReadOnly
is useless for existing files, anyway.Trying to set any file times for files that can only be accessed via privilege elevation require the BackupSemantics flag to be in play. It is currently not possible to use AlphaFS to set file times for files that are "blocked" for the current user (e.g. no effective allow ACEs in play), even if that user has the ability to override security checks via the Restore privilege.
I'm not sure why the distinction is made between files and folders for this function. My local fix is to simply always set the BackupSemantics flag, and remove the check for isFolder. However, once that is done, this function no longer has any use for the isFolder parameter, and all calling functions should be cleaned up to not pass this parameter anymore.
Let me know if I should create a patch for this function and all calling functions, and whether there is some other functionality or side effect I'm just missing here as for why this was setup this way in the first place.
Thanks!