This is the mail archive of the cygwin-apps@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re[2]: setup.exe and inuse files for X


Hello Robert,

Friday, May 03, 2002, 1:58:28 AM, you wrote:

>> -----Original Message-----
>> From: Corinna Vinschen [mailto:cygwin-apps@cygwin.com] 
>> Sent: Friday, May 03, 2002 1:44 AM
>> To: CygWin Apps; Cygwin-Xfree
>> Subject: Re: setup.exe and inuse files for X
>> 
>> 
>> On Wed, May 01, 2002 at 04:58:36PM +1000, Robert Collins wrote:
>> > I think I've got a handle on this... looks like read only 
>> (-r--r--r--) 
>> > files don't delete properly, so setup fails to overwrite them.
>> > 
>> > Patches gratefully accepted, it's going in the TODO for now.
>> 
>> I recall having sent a patch for this a few months ago to the 
>> cygwin-apps list...

RC> Yes. And I had implemented similar code. (Including the
RC> SetFileAttributes call).

RC> I'm not sure why it is still failing to do what it should. 

Check this out:

Quoted from the description of DeleteFile in the MDSN library:
To delete or rename a file, you must have either delete permission on the file
or delete child permission in the parent directory. If you set up a directory with
all access except delete and delete child and the ACLs of new files are inherited,
then you should be able to create a file without being able to delete it. However,
you can then create a file, and you will get all the access you request on the handle
returned to you at the time you create the file. If you requested delete permission
at the time you created the file, you could delete or rename the file with that handle
but not with any other.

ACL of a mode 400 file from my home directory:
C:\cygwin\home\paveltz\test.c MORDOR\paveltz:(accesso speciale:)
                                             READ_CONTROL
                                             WRITE_DAC
                                             WRITE_OWNER
                                             SYNCHRONIZE
                                             FILE_GENERIC_READ
                                             FILE_READ_DATA
                                             FILE_READ_EA
                                             FILE_WRITE_EA
                                             FILE_READ_ATTRIBUTES
                                             FILE_WRITE_ATTRIBUTES
 
                              MORDOR\Nessuno:(accesso speciale:)
                                             READ_CONTROL
                                             FILE_READ_EA
                                             FILE_READ_ATTRIBUTES
 
                              Everyone:(accesso speciale:)
                                       READ_CONTROL
                                       FILE_READ_EA
                                       FILE_READ_ATTRIBUTES

Obviously the DELETE permission is missing. You call SetFileAttributes
with ~FILE_ATTRIBUTE_READONLY which shoul enable the file for reading
but it does not - I suppose this is why:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/filesio_6c8i.asp

Note that it is said:
dwFileAttributes
Specifies FAT-style attribute information for the file or directory.

But if we're on NTFS there is no joy :( I've tried a simple test with
SetFileAttributes and ~FILE_ATTRIBUTE_READONLY and it doesnt affect
the file at all.

Ok here is how to fix this issues I've just tried it on my XP Home and
it worked fine.

    HANDLE h = CreateFile("test.c",
                          DELETE,
                          0, // We want it all :)
                          NULL,
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_READONLY /*to be compatible*/
                          | FILE_FLAG_DELETE_ON_CLOSE, NULL);
    CloseHandle (h);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]