Am Sat, 28 Dec 2013 05:13:57 +0100 schrieb Martin Nowak <[email protected]>:
> On 12/28/2013 05:01 AM, Marco Leise wrote: > > Ok, so there is a compatibility field for the file attributes > > in a .zip file. So a .zip extractor has to version(Windows/Posix) > > anyway to check if the attributes for a given file are > > compatible with the host OS. Couldn't SetFileAttributes and > > chmod be called right there on the spot? > > It does in memory extraction, you have to set the attributes after > writing out the file. > https://github.com/D-Programming-Language/installer/pull/31 > https://d.puremagic.com/issues/show_bug.cgi?id=11789 > https://github.com/D-Programming-Language/installer/pull/33 Some backlog! So getAttributes was there already, the dmd installer script used a custom "setAttributes" to extract ZIP files, and so it was decided that setAttributes should be in Phobos, too. (in short) Don't kill me, but I think this version of setAttributes should stay local to create_dmd_release (or std.zip if it was extended to support extraction to the file system). In the most general use case it still requires a code block like this: bool useFileAttr = false; version (Posix) { useFileAttr = data.isMeantForPosix; } else version (Windows) { useFileAttr = data.isMeantForWindows; } if (useFileAttr) std.file.setAttributes(data.fileName, data.fileAttribs); Meaning it is (as far as I can see) only of use for external data blocks that contain OS specific file attributes in a shared 32-bit field and at that point it doesn't gain much over: version (Posix) { if (data.isMeantForPosix) chmod( toUTFz!(char*)(data.fileName), data.fileAttr ); } else version (Windows) { if (data.isMeantForWindows) SetFileAttributesW( toUTFz!(wchar*)(data.fileName), data.fileAttr ); } For Phobos we need portable solutions. But it is also clear that std.file.setAttributes cannot be replaced to 100% by a portable solution. The question is: Does portable code _care_ about setting each possible chmod flag or Windows file attribute? Or are the use cases much more limited there, like making a file read-only or querying if it is a directory? -- Marco
