Loading ...
Sorry, an error occurred while loading the content.

Patch 7.2.076

Expand Messages
  • Bram Moolenaar
    Patch 7.2.076 Problem: rename(from, to) deletes the file if from and to are not equal but still refer to the same file. E.g., on a FAT32 filesystem
    Message 1 of 6 , Dec 30, 2008
    • 0 Attachment
      Patch 7.2.076
      Problem: rename(from, to) deletes the file if "from" and "to" are not equal
      but still refer to the same file. E.g., on a FAT32 filesystem
      under Unix.
      Solution: Go through another file name.
      Files: src/fileio.c


      *** ../vim-7.2.075/src/fileio.c Fri Nov 28 21:26:50 2008
      --- src/fileio.c Tue Dec 30 16:04:44 2008
      ***************
      *** 6119,6124 ****
      --- 6119,6165 ----
      if (mch_stat((char *)from, &st) < 0)
      return -1;

      + #ifdef UNIX
      + {
      + struct stat st_to;
      + char tempname[MAXPATHL + 1];
      +
      + /* It's possible for the source and destination to be the same file.
      + * This happens when "from" and "to" differ in case and are on a FAT32
      + * filesystem. In that case go through a temp file name. */
      + if (mch_stat((char *)to, &st_to) >= 0
      + && st.st_dev == st_to.st_dev
      + && st.st_ino == st_to.st_ino)
      + {
      + /* Find a name that doesn't exist and is in the same directory.
      + * Move "from" to "tempname" and then to "to". */
      + if (STRLEN(from) >= MAXPATHL - 5)
      + return -1;
      + STRCPY(tempname, from);
      + for (n = 123; n < 99999; ++n)
      + {
      + sprintf(gettail(tempname), "%d", n);
      + if (mch_stat(tempname, &st_to) < 0)
      + {
      + if (mch_rename((char *)from, tempname) == 0)
      + {
      + if (mch_rename(tempname, (char *)to) == 0)
      + return 0;
      + /* Strange, the second step failed. Try moving the
      + * file back and return failure. */
      + mch_rename(tempname, (char *)from);
      + return -1;
      + }
      + /* If it fails for one temp name it will most likely fail
      + * for any temp name, give up. */
      + return -1;
      + }
      + }
      + return -1;
      + }
      + }
      + #endif
      +
      /*
      * Delete the "to" file, this is required on some systems to make the
      * mch_rename() work, on other systems it makes sure that we don't have
      *** ../vim-7.2.075/src/version.c Wed Dec 24 14:24:41 2008
      --- src/version.c Tue Dec 30 16:09:51 2008
      ***************
      *** 678,679 ****
      --- 678,681 ----
      { /* Add new patch number below this line */
      + /**/
      + 76,
      /**/

      --
      FATAL ERROR! SYSTEM HALTED! - Press any key to continue doing nothing.

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ download, build and distribute -- http://www.A-A-P.org ///
      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... [...] Compiles OK, but: fileio.c: In function ‘vim_rename’: fileio.c:6141: warning: pointer targets in passing argument 1 of ‘gettail’ differ in
      Message 2 of 6 , Dec 30, 2008
      • 0 Attachment
        On 30/12/08 16:16, Bram Moolenaar wrote:
        >
        > Patch 7.2.076
        > Problem: rename(from, to) deletes the file if "from" and "to" are not equal
        > but still refer to the same file. E.g., on a FAT32 filesystem
        > under Unix.
        > Solution: Go through another file name.
        > Files: src/fileio.c
        [...]

        Compiles OK, but:
        fileio.c: In function ‘vim_rename’:
        fileio.c:6141: warning: pointer targets in passing argument 1 of
        ‘gettail’ differ in signedness
        fileio.c:6141: warning: pointer targets in passing argument 1 of
        ‘sprintf’ differ in signedness


        Best regards,
        Tony.
        --
        We have the flu. I don't know if this particular strain has an
        official name, but if it does, it must be something like "Martian Death
        Flu". You may have had it yourself. The main symptom is that you wish
        you had another setting on your electric blanket, up past "HIGH", that
        said "ELECTROCUTION".

        Another symptom is that you cease brushing your teeth, because (a) your
        teeth hurt, and (b) you lack the strength. Midway through the brushing
        process, you'd have to lie down in front of the sink to rest for a
        couple of hours, and rivulets of toothpaste foam would dribble sideways
        out of your mouth, eventually hardening into crusty little toothpaste
        stalagmites that would bond your head permanently to the bathroom
        floor, which is how the police would find you.

        You know the kind of flu I'm talking about.
        -- Dave Barry, "Molecular Homicide"

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Dominique Pelle
        ... [...] Will the stat() technique to find whether 2 files are identical work on all FAT file systems? I think remembering that FAT file systems don t have
        Message 3 of 6 , Dec 30, 2008
        • 0 Attachment
          Bram Moolenaar wrote:

          > Patch 7.2.076
          > Problem: rename(from, to) deletes the file if "from" and "to" are not equal
          > but still refer to the same file. E.g., on a FAT32 filesystem
          > under Unix.
          > Solution: Go through another file name.
          > Files: src/fileio.c
          >
          >
          > *** ../vim-7.2.075/src/fileio.c Fri Nov 28 21:26:50 2008
          > --- src/fileio.c Tue Dec 30 16:04:44 2008
          > ***************
          > *** 6119,6124 ****
          > --- 6119,6165 ----
          > if (mch_stat((char *)from, &st) < 0)
          > return -1;
          >
          > + #ifdef UNIX
          > + {
          > + struct stat st_to;
          > + char tempname[MAXPATHL + 1];
          > +
          > + /* It's possible for the source and destination to be the same file.
          > + * This happens when "from" and "to" differ in case and are on a FAT32
          > + * filesystem. In that case go through a temp file name. */
          > + if (mch_stat((char *)to, &st_to) >= 0
          > + && st.st_dev == st_to.st_dev
          > + && st.st_ino == st_to.st_ino)
          > + {
          [...]

          Will the stat() technique to find whether 2 files are identical work on
          all FAT file systems?

          I think remembering that FAT file systems don't have the concept of
          inodes, unlike Unix file systems, so stat() either leaves st_ino as 0,
          or synthesizes a fake inode number. I will try it later when I have time.

          -- Dominique

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Bram Moolenaar
          ... Inodes must work on any file system. It is a basic concept in Unix. If st_ino doesn t have a valid value that you should not use that file system, many
          Message 4 of 6 , Dec 31, 2008
          • 0 Attachment
            Dominique Pelle wrote:

            > Bram Moolenaar wrote:
            >
            > > Patch 7.2.076
            > > Problem: rename(from, to) deletes the file if "from" and "to" are not equal
            > > but still refer to the same file. E.g., on a FAT32 filesystem
            > > under Unix.
            > > Solution: Go through another file name.
            > > Files: src/fileio.c
            > >
            > >
            > > *** ../vim-7.2.075/src/fileio.c Fri Nov 28 21:26:50 2008
            > > --- src/fileio.c Tue Dec 30 16:04:44 2008
            > > ***************
            > > *** 6119,6124 ****
            > > --- 6119,6165 ----
            > > if (mch_stat((char *)from, &st) < 0)
            > > return -1;
            > >
            > > + #ifdef UNIX
            > > + {
            > > + struct stat st_to;
            > > + char tempname[MAXPATHL + 1];
            > > +
            > > + /* It's possible for the source and destination to be the same file.
            > > + * This happens when "from" and "to" differ in case and are on a FAT32
            > > + * filesystem. In that case go through a temp file name. */
            > > + if (mch_stat((char *)to, &st_to) >= 0
            > > + && st.st_dev == st_to.st_dev
            > > + && st.st_ino == st_to.st_ino)
            > > + {
            > [...]
            >
            > Will the stat() technique to find whether 2 files are identical work on
            > all FAT file systems?
            >
            > I think remembering that FAT file systems don't have the concept of
            > inodes, unlike Unix file systems, so stat() either leaves st_ino as 0,
            > or synthesizes a fake inode number. I will try it later when I have time.

            Inodes must work on any file system. It is a basic concept in Unix. If
            st_ino doesn't have a valid value that you should not use that file
            system, many tools will not work.

            --
            People who want to share their religious views with you
            almost never want you to share yours with them.

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ download, build and distribute -- http://www.A-A-P.org ///
            \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Bram Moolenaar
            ... I quickly fixed the serious problem that a file could be deleted when renaming it. I m now also fixing that rename( foo , FOO ) doesn t work on systems
            Message 5 of 6 , Dec 31, 2008
            • 0 Attachment
              Tony Mechelynck wrote:

              > On 30/12/08 16:16, Bram Moolenaar wrote:
              > >
              > > Patch 7.2.076
              > > Problem: rename(from, to) deletes the file if "from" and "to" are not equal
              > > but still refer to the same file. E.g., on a FAT32 filesystem
              > > under Unix.
              > > Solution: Go through another file name.
              > > Files: src/fileio.c
              > [...]
              >
              > Compiles OK, but:
              > fileio.c: In function ‘vim_rename’:
              > fileio.c:6141: warning: pointer targets in passing argument 1 of
              > ‘gettail’ differ in signedness
              > fileio.c:6141: warning: pointer targets in passing argument 1 of
              > ‘sprintf’ differ in signedness

              I quickly fixed the serious problem that a file could be deleted when
              renaming it. I'm now also fixing that rename("foo", "FOO") doesn't work
              on systems where the file name case is kept but ignored when finding a
              file. I'll also fix the warnings.

              --
              The most powerful force in the universe is gossip.

              /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
              /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
              \\\ download, build and distribute -- http://www.A-A-P.org ///
              \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_dev" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Tony Mechelynck
              ... [...] ... FAT filesystems have the concept of cluster number which is an integer between 2 and (at most) 2^n-16 (I think) (where n=12, 16 or 32 depending
              Message 6 of 6 , Dec 31, 2008
              • 0 Attachment
                On 31/12/08 14:58, Bram Moolenaar wrote:
                > Dominique Pelle wrote:
                [...]
                >> I think remembering that FAT file systems don't have the concept of
                >> inodes, unlike Unix file systems, so stat() either leaves st_ino as 0,
                >> or synthesizes a fake inode number. I will try it later when I have time.
                >
                > Inodes must work on any file system. It is a basic concept in Unix. If
                > st_ino doesn't have a valid value that you should not use that file
                > system, many tools will not work.
                >

                FAT filesystems have the concept of "cluster number" which is an integer
                between 2 and (at most) 2^n-16 (I think) (where n=12, 16 or 32 depending
                on the FAT type) and representing the ordinal location on the partition
                (or diskette) of a block of data which must be allocated as a unit. The
                cluster size (as a number of physical records) is determined when the
                partition is formatted; it is usually 512 bytes times a power of 2. The
                directory entry for every file (or subdirectory) includes the number of
                its first cluster; the FAT (File Allocation Table) entry for every
                cluster on the partition holds either the number of the next cluster in
                the same file, or a code meaning that this is the last cluster of the
                file, that it is not allocated to any file, or that it is a known bad
                cluster. I'm not 100% sure what an "inode" means on Unix filesystems but
                I think this is the FAT equivalent.

                Best regards,
                Tony.
                --
                There is a theory which states that if ever anyone discovers exactly
                what the Universe is for and why it is here, it will instantly
                disappear and be replaced by something even more bizarre and
                inexplicable. There is another theory which states that this has
                already happened.
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_dev" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              Your message has been successfully submitted and would be delivered to recipients shortly.