git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: chmod failure on GVFS mounted CIFS share

From
KPKonrad Bucheli (PSI) <konrad.bucheli@psi.ch>
Date
Dec 20, 2024, 15:50 UTC
Message-ID
<8af7ff11-c5bb-464b-894f-f1fb30df50e0@psi.ch>
In-Reply-To
<xmqq8qsafjfy.fsf@gitster.g>
On 20.12.24 16:44, Junio C Hamano wrote:
Show 9 quoted lines
> "Konrad Bucheli (PSI)" <konrad.bucheli@psi.ch> writes:
> 
>> I have another idea: there is no need for a chmod if both the config
>> file and the lock file already have he same mode. Which is the case if
>> the filesystem has no proper chmod support.
> 
> And for majority of people who have working chmod(), would it mean
> one extra and unnecessary system call?
> 

I do not have stats, but I guess the chmod call would be needed very rarely as most of the time both files have default permissions. I do not know which call is more expensive.

Show 19 quoted lines
> Instead, how about doing the chmod() first, like we have always done,
> but after seeing it fail, check with lstat() to see if the modes are
> already in the desired state and refrain from complaining if that is
> the case?  That way, we'll incur extra overhead only in the error
> code path, which is the usual pattern we would prefer to do things.
> 
> So instead of removing this part, ...
> 
>> -		if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
>> -			error_errno(_("chmod on %s failed"), get_lock_file_path(&lock));
> 
> ... you'd do an extra lstat() on the lock file (so you can move the
> st_lock inside this block, narrowing its scope) before calling
> error_errno(), and only after finding out that st_lock cannot
> somehow be obtained or the resulting mode is different, you call
> error_errno() and arrange an error to be returned, all inside the
> if(){} block of the original.
> 
> Wouldn't it work even better, I wonder?
If you think that is the way to go, I will adapt the patch.
Show 21 quoted lines
> 
> Thanks.
> 
>> +		if (stat(get_lock_file_path(&lock), &st_lock) == -1) {
>> +			error_errno(_("stat on %s failed"), get_lock_file_path(&lock));
>>   			ret = CONFIG_NO_WRITE;
>>   			goto out_free;
>>   		}
>>   
>> +		if ((st.st_mode & 07777) != (st_lock.st_mode & 07777)) {
>> +			if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
>> +				error_errno(_("chmod on %s failed"), get_lock_file_path(&lock));
>> +				ret = CONFIG_NO_WRITE;
>> +				goto out_free;
>> +			}
>> +		}
>> +
>>   		if (store.seen_nr == 0) {
>>   			if (!store.seen_alloc) {
>>   				/* Did not see key nor section */
> 
Previous: Junio C HamanoNext: Konrad Bucheli (PSI)
Message 7 of 8 in “chmod failure on GVFS mounted CIFS share”
  1. Konrad Bucheli (PSI)Dec 12, 2024
  2. brian m. carlsonDec 13, 2024
  3. Konrad Bucheli (PSI)Dec 13, 2024
  4. brian m. carlsonDec 15, 2024
  5. Konrad Bucheli (PSI)Dec 20, 2024
  6. Junio C HamanoDec 20, 2024
  7. Konrad Bucheli (PSI)Dec 20, 2024
  8. Konrad Bucheli (PSI)Jan 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.