Euphoria
Ticket #899:
move_file can sometimes report success on failure
-
Reported by
SDPringle
Jun 18, 2014
You need Linux and a flashdrive and a file with weird characters:
- Mount your flashdrive (using your GUI tool or mount if you are old school)
- Create move.ex below but change the source_dir and dest_dir to somewhere on your home directory and to where your flashdrive is mounted, respectively
- create a file with this name: "20 de Junio - Día de la Bandera Argentina.dat" in your source_dir
- run move.ex
move.ex:
include std/filesys.e
include std/search.e
include std/io.e as io
include std/os.e as os
-- include trailing slashes!
constant source_dir = "/home/shawn/downloads/"
constant dest_dir = "/media/FlashDrive/"
sequence s = dir(source_dir & "*.dat")
for i = 1 to length(s) do
sequence d_ent = s[i]
sequence d_name = d_ent[D_NAME]
if match("20 de", d_name) = 1 then
printf(io:STDOUT, "Found %s in downloads\n", {d_name})
if not move_file(source_dir & d_name, dest_dir & d_name) then
puts(io:STDERR, "Could not move " & d_name & " to flash drive.\n")
else
os:sleep(1)
printf(io:STDERR, "move_file reports the file %s has been successfully moved ", {d_name})
if file_exists(dest_dir & d_name) then
puts(io:STDERR, "and so it has.\n")
else
puts(io:STDERR, "but it hasn't.\n")
end if
end if
end if
end for
You should get:
Found 20 de Junio - Día de la Bandera Argentina.dat in downloads
move_file reports the file 20 de Junio - Día de la Bandera Argentina.dat has been successfully moved and so it has.
but I get:
Found 20 de Junio - Día de la Bandera Argentina.dat in downloads
move_file reports the file 20 de Junio - Día de la Bandera Argentina.dat has been successfully moved but it hasn't.
Both mv and KDE's file manager programs report error creating destination. I think the Linux driver doesn't support the 'í' on vfat but it does on ext2fs and so all other programs report an error when trying to move the file. move_file() should report failure as well.
Details
1. Comment by SDPringle
Jun 18, 2014
Anytime there is another filesystem involved this routine inverts the success code which is okay when the success code is from UNIX C routines but not okay when calling other std/filesys.e routines. I am preparing a fix for this.
2. Comment by mattlewis
Jun 18, 2014
That's very odd. I would guess that the problem is actually inside of copy_file(), and really in open(). Can you open a file for writing with that name on a VFAT disk?
I was able to open a file for writing with that name on VFAT.
3. Comment by SDPringle
Jun 18, 2014
See: hg:euphoria/rev/a0120f6dc562
changeset: 6235:a0120f6dc562 tag: tip parent: 6218:d564cc9bc164 user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Jun 18 09:18:42 2014 -0300 files: include/std/filesys.e description:
- fixed move_file to return correct success code in the case of UNIX between distinct filesystems
- limit the scope of ret
- fixes ticket 899
4. Comment by SDPringle
Jun 18, 2014
See: hg:euphoria/rev/faffe693f1dc
changeset: 6236:faffe693f1dc tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Jun 18 09:32:33 2014 -0300 files: include/std/filesys.e description:
5. Comment by SDPringle
Jun 18, 2014
@mattlewis The failure to move the file itself seems to be some kind of bug specific for my version of Linux. I cannot create 'Ah?.txt' with the touch command.
6. Comment by jimcbrown
Jun 18, 2014
You can probbaly fix the original issue by playing with the codepage option to vfat: http://www.linuxquestions.org/questions/slackware-14/how-to-set-default-mount-codepage-for-vfat-partition-as-utf8-740681/
See also https://www.kernel.org/doc/Documentation/filesystems/vfat.txt
For others to reproduce the bug, maybe try to use the colon character : in the filename - that's illegal on vfat. Of course, newer kernels might have an option to emulate the colon character on vfat by encoding it differently or something....
7. Comment by SDPringle
Jun 18, 2014
You can reproduce the bug much more easily if you are talking about that of this ticket.
bash-4.2# dd if=/dev/zero of=/tmp/tmpfs.fs bs=1k count=1000
1000+0 records in
1000+0 records out
1024000 bytes (1.0 MB) copied, 0.0101574 s, 101 MB/s
bash-4.2# mkfs -t minix /tmp/tmpfs.fs
352 inodes
1000 blocks
Firstdatazone=15 (15)
Zonesize=1024
Maxsize=268966912
bash-4.2# mkdir /media/FlashDrive;
bash-4.2# mount /tmp/tmpfs.fs /media/FlashDrive -t minix -o loop,rw
bash-4.2# su shawn
bash-4.2$ cd
bash-4.2$ touch ~/downloads/'20 de Junio.dat'
bash-4.2$ cp ~/downloads/'20 de Junio.dat' /media/FlashDrive
cp: cannot create regular file '/mnt/tmp/ex.err': Permission denied
bash-4.2$ eui move.ex
Found 20 de Junio.dat in downloads
move_file reports the file 20 de Junio.dat has been successfully moved but it hasn't.