chown when the file already exists?

John Arbash Meinel john at arbash-meinel.com
Thu Mar 25 18:47:24 GMT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


...
>> The big problem is "has_chown = getattr()" raises an exception if you
>> only use the 2 parameter form. However, this showed another issue.

So I submitted a fix for this because otherwise bzr.dev on windows just
fails to start.


>>
>> Why is "bzr status" thinking about calling chown? Digging into it, I see
>> it is being called from:
>>
>> def open_with_ownership()
>>
>> Which is being called for opening .bzr.log... However, if we aren't
>> creating the file, should we be changing its ownership?
>>



> 
> Hi John,
> 
> This issue was introduced by me in the mp for bug #376388 [1].
> Missed out on the importance of 'a' :-)
> 
> Specifically, in trace.py:
> - bzr_log_file = open(_bzr_log_filename, 'at', buffering=0) # unbuffered
> + buffering = 0 # unbuffered
> + bzr_log_file = osutils.open_with_ownership(_bzr_log_filename, 'at', buffering)
> 
> I am not sure whats a good way to handle this. We could go back to
> using open() and chown only if the log file didn't exist before the open using a
> flag to check this.
> 
> I could do an mp for this. Please let me know if you have any other suggestions.
> 
> Regards,
> Parth
> 
> [1] https://code.launchpad.net/~parthm/bzr/376388-dot-bazaar-ownership/+merge/19691
> 

I don't have a great answer for it. IMO, I think if the file doesn't
exist, we should create it and inherit the permissions from the
containing directory. Otherwise we should just open it and write to it.

Otherwise, people who have their file set in a specific way are going to
have it clobbered.

I don't know of a way to open() for append/writing and know whether you
created the file. There is probably O_EXIST on the raw os.open()
function, but I don't know if it is that critical. Probably just stat
for the file, if that fails, then we'll set the ownership. (It is only 1
stat per startup.)

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkurr7wACgkQJdeBCYSNAAMexgCeNiz4wYY4j01X2mBSMOZAlD3+
vFcAoIyZeIpq5KejJbpO/QjMKsvyJhc4
=gJ+b
-----END PGP SIGNATURE-----



More information about the bazaar mailing list