Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"std.file.copy" now completely ignores the "PreserveAttributes.no" argument on Windows #10349

Open
dlangBugzillaToGithub opened this issue Sep 4, 2018 · 1 comment
Labels
OS:Windows Issues Specific to Windows Severity:Normal

Comments

@dlangBugzillaToGithub
Copy link

bugzilla (@WalterBright) reported this on 2018-09-04T21:45:14Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=19221

Description

On 04/09/2018 10:27 PM, Ecstatic Coder wrote:
> On Tuesday, 4 September 2018 at 09:56:13 UTC, rikki cattermole wrote:
>> On 04/09/2018 9:40 PM, Ecstatic Coder wrote:
>>> But it seems that the latest version of "std.file.copy" now completely ignores the "PreserveAttributes.no" argument on Windows, which made recent Windows builds of Resync fail on read-only files.
>>
>> What???
>>
>> There is nothing in the changelog between 2.080.0 and 2.082.0 for changes to std.file.
>>
>> Version from July 2017[0]. Version from 2.082.0[1]. They look the same to me.
>>
>> [0] https://github.com/dlang/phobos/blob/d8959320e0c47a1861e32bbbf6a3ba30a019798e/std/file.d#L3430
>> [1] https://github.com/dlang/phobos/blob/v2.082.0/std/file.d#L4216
>
> Mayb I'm wrong, but what I can say is that I've recently updated DMD and compiled a windows build of Resync, and that I *HAD* to make Windows-specific code that removes the "read-only" attributes only on Windows.
>
> attributes = source_file_path.getAttributes();
> source_file_path.getTimes( access_time, modification_time );
>
> version ( Windows )
> {
>      if ( target_file_path.exists() )
>      {
>          target_file_path.setAttributes( attributes & ~1 );
>      }
>
>      source_file_path.copy( target_file_path, PreserveAttributes.no );
>      target_file_path.setAttributes( attributes & ~1 );
>      target_file_path.setTimes( access_time, modification_time );
>      target_file_path.setAttributes( attributes );
> }
> else
> {
>      if ( target_file_path.exists() )
>      {
>          target_file_path.setAttributes( 511 );
>      }
>
>      source_file_path.copy( target_file_path, PreserveAttributes.no );
>      target_file_path.setAttributes( attributes );
>      target_file_path.setTimes( access_time, modification_time );
> }
>
> Honestly I don't see why I have to make this ugly fix on Windows, while the Linux version has always worked fine on read-only files.

Hang on a second.

assert(preserve == Yes.preserveAttributes);

Something is smelling an awful lot here.

Up to Windows 7 CopyFileW which is used for Windows didn't copy the attributes over[0] but it does now.

This is a bug on our end, which should include a fallback to copying manually the file contents over.

[0] https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-copyfilew
@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2018-09-04T21:46:03Z

(above was posted by Rick Cattermole)

@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS:Windows Issues Specific to Windows Severity:Normal
Projects
None yet
Development

No branches or pull requests

2 participants