New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process is preventing itself from copying files #80
Comments
test |
Findings:
So the locking mechanism is NOT about processes having locks that prevent other processes from using (even reading) a file. The JavaDoc of the moronic FileLock class (hardly any JavaDoc, hardly any useful methods, two methods that do the same, etc) talks about "Other programs", meaning processes (in professional terms, but whatever). This means that if it prevents the same process, the same THREAD even, from using the file without any mentioning, this is a bug. Either in botchy Reinhold's code itself or in the windows implementation (that maybe he wrote, too). That also explains the plain simply wrong exception message: they (he?) just wrote buggy code and the exception is the result visible to the calling context. So far regarding flaming JDK idiocy for about the 100th time. I don't want to go back to streams because they are "old", NIO is usally more efficient/fast and I read somewhere that creating a lock on a stream-based FileChannel only locks the stream and not the actual file. Which, of course, is another JDK idiocy and explains why other windows tools (like hexeditor) didn't give a sh*t about the lock I created via stream-based FileChannels back when initially developing and testing the storage file accessing. And that means, once again: to get a proper solution, the basic JDK functionality has to be replaced by a self-written solution. |
ZJ suggested to just copy the method from Apache's FileUtils class to avoid the dependency for just one method. That seems to be a good idea. |
I am not 100% sure if this is the most recent version of apache-io, but the source code for FileUtils#doCopyFile (the code that does the actual copying) just calls the same JDK method that the MicroStream framework currently calls, Files#copy
Does copying a locked source file really work with this? It's exactely the same plus weird extras. |
The linked source code is not the current version.
This would either have to be overhauled a little or replaced by direct FileChannel opening without the streams detour. Except if that suffers from the bug, too, then streams as a fallback. |
I tested around a little and found that the apache code is too weird to be used:
All that is required for a working replacement for
That's like 4 line of code, INCLUDING resource handling. (As stated above, whereever I look, I only see weird, botchy, half-baked code that should better not be used). So I extended the XIO utility class with a In the simplest case, it suffices to call If ensuring the target file or other special case handling is required, calls like I will replace all occurances of the buggy JDK Files#copy method with calls to the new method. |
All occurances of JDK Files#copy have been replaced with XIO#copyFile. |
JDK moronity strikes again. The following code snippet:
Causes the following exception with a completely wrong and useless message:
source.txt -> target.bak: Der Prozess kann nicht auf die Datei zugreifen, da ein anderer Prozess einen Teil der Datei gesperrt hat.
(I won't translate that here and showing system messages in a localized form is another moronity in itself, but whatever)
It seems that the recent switch from File to Path and the associated change from opening a FileChannel via an InputStream to the actually more modern and supposedly better FileChannel#open method caused this behavior.
Maybe Files#copy doesn't work if there is an open FileChannel oder an existing FileLock or whatever.
Or it need a "Create target file if it does not exist, yet"-option.
Whatever the reason is, it is definitely NOT that another process has locked any of the two files involved, because there is no such process.
If someone needs me, I'll be knee-deep in researching JDK idiocy once again...
The text was updated successfully, but these errors were encountered: