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

Re: [PATCH] handle rename of case only, for windows

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Jan 14, 2011, 14:17 UTC
Message-ID
<AANLkTinbnYzTqP5-vA4hJqSgSBBjJrx8LCsq5G3nVmFW@mail.gmail.com>
In-Reply-To
<1295012644.7883.1415296115@webmail.messagingengine.com>
On Fri, Jan 14, 2011 at 8:44 PM, Tim Abell <tim@timwise.co.uk> wrote:
Show 36 quoted lines
>                else if (lstat(dst, &st) == 0) {
> -                       bad = "destination exists";
> -                       if (force) {
> -                               /*
> -                                * only files can overwrite each other:
> -                                * check both source and destination
> -                                */
> -                               if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
> -                                       warning("%s; will overwrite!", bad);
> -                                       bad = NULL;
> -                               } else
> -                                       bad = "Cannot overwrite";
> +                       /* If we are on a case insensitive files= system (windows) http://is.gd/kyxgg
> +                        * and we are only changing the case of the file then lstat for the
> +                        * destination will return != 0 because it sees the source file.
> +                        * To prevent this causing failure, lstat is used to get the inode of the src
> +                        * and see if it's actually the same file.
> +                        */
> +                       lstat(src, &src_st); //get file serial number (inode) for source
> +                       #warning("src inode: %s, dst inode: %s", src_st.st_ino, st.st_ino);
> +                       if (src_st.st_ino != st.st_ino) {
> +                               bad = "destination exists";
> +                               if (force) {
> +                                       /*
> +                                        * only files can overwrite each other:
> +                                        * check both source and destination
> +                                        */
> +                                       if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
> +                                               warning("%s; will overwrite!", bad);
> +                                               bad = NULL;
> +                                       } else
> +                                               bad = "Cannot overwrite";
> +                               }
>                        }
>                } else if (string_list_has_string(&src_for_dst, dst))
>                        bad = "multiple sources for the same target";

I wonder if we can make lstat_case() that would only return 0 if it matches exactly the filename, even on FAT. FindFirstFile/FindNextFile should return true file name, I think. If not, we can make lstat_case() take two paths (src and dst) and move all inode comparison code in there. Much cleaner.

-- 
Duy
Previous: Tim Abell
Message 2 of 2 in “handle rename of case only, for windows”
  1. handle rename of case only, for windowsTim Abell, Jan 14, 2011
  2. Nguyen Thai Ngoc DuyJan 14, 2011

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.