file renaming needs a rewrite
Project: | JNode Core |
Component: | Code |
Category: | task |
Priority: | critical |
Assigned: | kinaeda |
Status: | patch (code needs review) |
The current method of file renaming is wrong and it does not work properly.
The culprit is in the classpath section of the classlibs, java.io.VMFile
The problem is obvious, the implementation for rename opens two streams (which dont close properly), and copies the contents from one file to the next, then deletes the original. Not only is this an expensive operation in some cases, but it also prevents directories from being renamed.
For this to be done properly would involve:
a) determine if the dest exists and if it does fail
b) determine if the source and dest have the same parent, if they do, simply rename the file
c) if the parents are different, determine if the dest parent is on a different filesystem from the source parent. If not, then link the file from the dest dir and unlink from the source dir
d) if the parents are different and the dest parent is on a different filesystem, copy the file via streams and delete the source once complete
Im not sure why this has been overlooked so long, and im guessing its why we have no mv command, which im in the process of doing, but got stumped on this issue.
- Login to post comments
#1
I done a recode of this. Couldn't find a way to determine if the files were on different filesystems but the rest I did. I attached the new VMFile.java below.
#2
Please send it as a patch and not as plain java file.
It's better to know and check what you did, especially without knowing the version of VMFile that you have modified.
#3
here are kinaeda's changes as a patch