2008/12/29 Charles Campbell skribis:
> Charles Campbell wrote:
>>
>> Well, its lunchtime -- and I've done it -- and it appears to be a vim
>> problem. Netrw is in fact calling vim's rename() function; but with
>> full paths.
>>
>> :call rename("..fullpath../1.pdf","..fullpath../1.PDF")
>>
>> causes the 1.pdf file to be removed.
>>
> Further... I suspect its vim_rename()'s problem (internal, fileio.c).
> The code removes the "to" file prior to moving the "from" file.
> For the Amiga, it locks the "from" file first (and later unlocks it) to
> prevent just this sort of problem -- but there is no such protection
> using linux to rename a fat32-mounted file.
>
> Regards,
> Chip Campbell
Yes, the problem is there.
The attached patch tries a normal mch_rename() *before*
deleting the destination file. It does so only for Unix-like
systems (#ifdef UNIX) to avoid any risk of breaking other
systems, since the existing comment said...
Delete the "to" file, this is required on some systems [...]
If mch_rename() fails, it then proceeds as before (i.e. delete
destination, then tries to mch_rename() again).
I tested it with FAT-32 (on Linux). With the patch, it prevents
the file from being deleted (good) but trying to rename
foo.pdf into foo.PDF does not do anything. mch_rename(),
[i.e. system call rename() on Linux], returns success even
though it does not do anything. In any case, the file is not
removed at least.
Trying "mv foo.PDF foo.pdf" in a shell gives an error:
$ mv foo.PDF foo.pdf
mv: `foo.PDF' and `foo.pdf' are the same file
I tried renaming foo.PDF into foo.pdf with GNOME Nautilus
and it does not let rename the file either.
But the workaround of renaming file in 2 steps (in Vim or
in shell) works fine which shows that it should be possible
to rename files somehow even though only lower/uppercase
changes:
$ mv foo.PDF foo.PDF.tmp
$ mv foo.PDF.tmp foo.pdf
I wonder whether the fact that system call rename("foo.pdf", "foo.PDF")
does not do anything on FAT-32 can be considered as a bug
in FAT-32 implementation on Linux.
Regards
-- Dominique
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: fileio.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/fileio.c,v
retrieving revision 1.127
diff -c -r1.127 fileio.c
*** fileio.c 28 Nov 2008 20:27:53 -0000 1.127
--- fileio.c 29 Dec 2008 19:24:44 -0000
***************
*** 6120,6125 ****
--- 6120,6133 ----
return -1;
/*
+ * First try a normal rename, return if it works.
+ */
+ #if UNIX
+ if (mch_rename((char *)from, (char *)to) == 0)
+ return 0;
+ #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
* two files when the mch_rename() fails.
***************
*** 6148,6154 ****
#endif
/*
! * First try a normal rename, return if it works.
*/
if (mch_rename((char *)from, (char *)to) == 0)
return 0;
--- 6156,6162 ----
#endif
/*
! * Try again with a normal rename, return if it works.
*/
if (mch_rename((char *)from, (char *)to) == 0)
return 0;