chown when the file already exists?

Parth Malwankar parth.malwankar at gmail.com
Fri Mar 26 04:36:17 GMT 2010


On Fri, Mar 26, 2010 at 12:17 AM, John Arbash Meinel
<john at arbash-meinel.com> wrote:
> -----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.
>

Thanks for finding the issue.
Sorry about that.

>>>
>>> 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.)
>

I have submitted an mp
https://code.launchpad.net/~parthm/bzr/no-chown-if-bzrlog-exists/+merge/22197

Regards,
Parth



More information about the bazaar mailing list