Editing with vim clears Windows 10 file system archive bit.
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Nov 15 20:05:06 GMT 2021
On Nov 15 19:54, Christian Franke wrote:
> Steve Ward via Cygwin wrote:
> > Description of problem:
> > While using vim 8.2 on cygwin 3.3 (x86_64) on Windows 10,
> > when editing an existing file with vim and saving it, the Window’s
> > file system archive bit is always left cleared (not modified state).
> > This happens, whether the archive bit was set (is modified) or
> > clear (not modified) initially.
>
> The problem also occurs with 'cp' command:
>
> $ touch file1
>
> $ /bin/cp file1 file2
>
> $ /bin/cp --preserve=mode file1 file3
>
> $ lsattr file?
> ---a-------- file1
> ---a-------- file2
> ------------ file3
>
> Some Cygwin functions apparently clear the archive attribute unexpectedly,
> for example:
>
> int fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0644);
> write(fd, "Test\n", 5);
> fchmod(fd, 0644); // clears archive attribute
> close(fd);
>
> Same with facl(., SETACL, ...). The variants chmod() and acl() are not
> affected.
It's funny that it took so long that somebody actually noticed this.
This behaviour is present at least since 2004. Cygwin *never* actually
cared for the ARCHIVE attribute explicitely. The reason for the above
observation is the open call containing the O_CREAT flag. When Cygwin
creates files, it sets the attributes to FILE_ATTRIBUTE_NORMAL only, not
adding the FILE_ATTRIBUTE_ARCHIVE flag.
Changing that is actually pretty simple, just set FILE_ATTRIBUTE_ARCHIVE
as soon as the underlying NtCreateFile is called for an open(O_CREAT).
Fixed in current git.
Thanks,
Corinna
More information about the Cygwin
mailing list