Repository navigation
Description
I am running Ubuntu WSL
I was running the following to find files with Windows-1252 encoding and convert them to UTF-8:
LC_ALL=C.UTF-8 find . -type f \( -name '*txt' -or -name '*html' -or -name '*htm' \) -exec grep -laxv '.*' {} + | xargs uchardet | grep WINDOWS-1252 | cut -d: -f1 | xargs -n 1 recode -t 'windows-1252..UTF-8'
Unfortunately it seems that recode does not work properly with NTFS filesystems at all
I ended up with hundreds of these messages:
recode: chmod (./path/path/rec4308.tmp): Operation not permitted
recode: chmod (./path/path/rec4309.tmp): Operation not permitted
recode: chmod (./path/path/rec4310.tmp): Operation not permitted
recode: chmod (./path/path/rec4311.tmp): Operation not permitted
recode: chmod (./path/path/rec4312.tmp): Operation not permitted
recode: chmod (./path/path/rec4313.tmp): Operation not permitted
recode: chmod (./path/path/rec4314.tmp): Operation not permitted
recode: chmod (./path/path/rec4315.tmp): Operation not permitted
recode: chmod (./path/path/rec4316.tmp): Operation not permitted
recode: chmod (./path/path/rec4317.tmp): Operation not permitted
recode: chmod (./path/path/rec4318.tmp): Operation not permitted
recode: chmod (./path/path/rec4319.tmp): Operation not permitted
recode: chmod (./path/path/rec4320.tmp): Operation not permitted
recode: chmod (./path/path/rec4321.tmp): Operation not permitted
All of the original files (and all filename information) are gone
The .tmp files are in fact UTF-8 but there's no way to know what the original filenames were so the files are effectively gone/useless
even if I had the original filenames there's no way to know which .tmp file correlates with which original filename
it's not uncommon for Linux programs to not work perfectly on NTFS but I've never encountered anything this bad before
I "lost" nearly 400 files and it would have been more if I hadn't noticed the errors and aborted the job
Here's an example using a single file:
$ file testfile
testfile: HTML document, ASCII text, with very long lines, with LF, NEL line terminators
$ uchardet testfile
WINDOWS-1250
$ recode -t 'windows-1250..UTF-8' testfile
recode: chmod (rec5087.tmp): Operation not permitted
$ ls testfile
ls: cannot access 'testfile': No such file or directory
$ ls *.tmp
rec5087.tmp
$ file *.tmp
rec5087.tmp: HTML document, UTF-8 Unicode text, with very long lines
$ uchardet *.tmp
WINDOWS-1250
$
With a single file it's not a big deal to rename the .tmp file back to the original filename (as long as you have the original filename) but when many files are affected it seems impossible to recover from, especially if you don't have the original filenames.
I verified the same thing happens even without the -t
I verified that this happens on both NTFS and exFAT but does NOT happen on FAT32
this issue might or might not be specific to WSL systems; a pure Linux system with an NTFS or exFAT filesystem mounted might or might not behave differently; I'm unable to test this
Activity
rrthomas commentedon Mar 28, 2022
Ouch! Sorry about your data loss, and thanks for such a detailed report. A first look at the code leaves me baffled, as the only call to
chmod()is made without caring about whether it succeeds (it's done on a "best effort" basis), so I can't work out how that error message is being emitted. I will investigate further.Please could you confirm what version of recode you're using?
catharsis71 commentedon Mar 28, 2022
I'm using the Ubuntu package which seems to be 3.6-24... am I in the wrong place? I didn't look too closely at the package info yesterday so I might be in the wrong place.
The --version on mine doesn't seem like it's been updated in quite a while
rrthomas commentedon Mar 28, 2022
I would certainly appreciate a report against the latest 3.7.x. I am working with Debian to get 3.7 packaged, but it's taking a while!
catharsis71 commentedon Mar 28, 2022
Okay on 3.7.12 it seems to work properly on NTFS but still fails in the same way on exFAT, albeit with a different error message, same end result though -- original file gone, .tmp file retained, and no easy way to figure out which .tmp file came from which file if you ran it on a lot of files.
exFAT filesystem:
NTFS filesystem:
I saw there was a --verbose option so I gave it a try on exFAT but it didn't provide a whole lot of info
This could possibly be a WSL bug or incompatibility. I should probably file a bug with WSL but it'd be useful to know if this happens on a pure Linux system to or only with WSL. Unfortunately I'm not able to test on pure Linux currently.
Just throwing out ideas, maybe the temp file name could just be the real filename with .tmp appended to it? That way if something goes wrong and you end up with a bunch of .tmp files you at least know what the names are supposed to be.
catharsis71 commentedon Mar 28, 2022
Doing further testing... it looks like 3.7.12 is broken on FAT32 filesystems as well, even though the older version worked properly on FAT32...
So in summary:
No issues on my native WSL filesystem which I think is ext4, but my space there is limited so I basically have to use my mounted Windows drives for a lot of stuff.
rrthomas commentedon Mar 28, 2022
Thanks for your further investigation.
If I try your example on a FAT32 filing system attached to my Ubuntu machine, it works fine, so the filing system doesn't appear to matter.
As you've observed, it's the
rename()system call that is failing, so the data is not (fortunately!) being lost in this case. However, I agree it would be no fun trying to recover it from the temporary files. TheNo such file or directoryerror suggests that therename()routine, at least, is having trouble with the filename. I assume that/mnt/eis really/home?At first blush it looks as though for some reason
rename()doesn't understand the filename while the other routines that open the file etc. understand it just fine. I'm afraid I don't know much about WSL, so I have no idea why this would be.rrthomas commentedon Mar 28, 2022
gnulibhas arename()wrapper thatrecodeis not currently using, but it doesn't have any code in it that references WSL. Some of therenametests do mention WSL, but none of the cases tested seem to relate to this one.[-]Disaster when running on an NTFS or exFAT filesystem[/-][+]Rename fails in some circumstances on WSL[/+]catharsis71 commentedon Mar 28, 2022
I filed a bug on WSL: microsoft/WSL#8201
The error message on 3.7 is definitely more useful than what I was initially encountering on 3.6, because it does actually show the original & temporary filename together. So on 3.7 at least, if the program output hasn't been lost, renaming the files back manually isn't a huge deal. The files I converted yesterday on 3.6 though are probably a lost cause
rrthomas commentedon Mar 28, 2022
Sorry I can't help more, and I hope someone at MS or with better knowledge of WSL can work out what's going wrong here. There may well be a fix or workaround even if it's not a recode bug.