Re: [PATCH 2/2] config: use chmod() instead of fchmod()
- From
Karsten Blees <karsten.blees@gmail.com>
- Date
- Jul 16, 2014, 10:53 UTC
- Message-ID
- <53C659B0.8040306@gmail.com>
- In-Reply-To
- <53C60E9C.3020604@kdbg.org>
Am 16.07.2014 07:33, schrieb Johannes Sixt:
Show 44 quoted lines
> Am 16.07.2014 00:54, schrieb Karsten Blees:
>> There is no fchmod() on native Windows platforms (MinGW and MSVC), and the
>> equivalent Win32 API (SetFileInformationByHandle) requires Windows Vista.
>>
>> Use chmod() instead.
>>
>> Signed-off-by: Karsten Blees <blees@dcon.de>
>> ---
>> config.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/config.c b/config.c
>> index ba882a1..9767c4b 100644
>> --- a/config.c
>> +++ b/config.c
>> @@ -1636,8 +1636,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
>> MAP_PRIVATE, in_fd, 0);
>> close(in_fd);
>>
>> - if (fchmod(fd, st.st_mode & 07777) < 0) {
>> - error("fchmod on %s failed: %s",
>> + if (chmod(lock->filename, st.st_mode & 07777) < 0) {
>> + error("chmod on %s failed: %s",
>> lock->filename, strerror(errno));
>> ret = CONFIG_NO_WRITE;
>> goto out_free;
>> @@ -1815,8 +1815,8 @@ int git_config_rename_section_in_file(const char *config_filename,
>>
>> fstat(fileno(config_file), &st);
>>
>> - if (fchmod(out_fd, st.st_mode & 07777) < 0) {
>> - ret = error("fchmod on %s failed: %s",
>> + if (chmod(lock->filename, st.st_mode & 07777) < 0) {
>> + ret = error("chmod on %s failed: %s",
>> lock->filename, strerror(errno));
>> goto out;
>> }
>>
>
> I assume you tested this patch on Windows. I am mildly surprised that
> (on Windows) chmod() works on a file that is still open.
>
> -- Hannes
> Yes, file attributes can be set independently of open files. In fact, existing code in git already does that in many places (via adjust_shared_perm(), which is typically called while the file is open).
-- -- *** Please reply-to-all at all times *** *** (do not pretend to know who is subscribed and who is not) *** *** Please avoid top-posting. *** The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free. You received this message because you are subscribed to the Google Groups "msysGit" group. To post to this group, send email to msysgit@googlegroups.com To unsubscribe from this group, send email to msysgit+unsubscribe@googlegroups.com For more options, and view previous threads, visit this group at http://groups.google.com/group/msysgit?hl=en_US?hl=en --- You received this message because you are subscribed to the Google Groups "msysGit" group. To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.