Which one is correct mv or Path#move?
Rajendra Gutupalli
Rajendra.Gutupalli at Sun.COM
Thu Jul 31 03:32:19 PDT 2008
Hi Alan,
I see difference in behavior between command mv and Path.move(). I
created and moved a hardlink to a assigned drive (using subst command )
for a directory in C:\.
After moving using mv the link count for the file to which hard link is
created is reduced but after moving Path.move I don't see any reduction
in link count.
Please see the following result in command line and using program.
But if I assign a drive for a network folder in C drive using net
command ( net use M \\rajendra\temp : where temp is in C drive)and move
the hard link to this drive I see link count is reduced in both cases
(ie. using mv and Path.move).
<command line>
C:\>touch testfile
C:\>ls -l testfile
-rwxrwxrwa 1 R.+Vittal None 0 Jul 31 13:35 testfile
C:\>fsutil hardlink create testfile_hl testfile
Hardlink created for C:\testfile_hl <<===>> C:\testfile
C:\>ls -l testfile
-rwxrwxrwa 2 R.+Vittal None 0 Jul 31 13:35
testfile (link count here is 2)
C:\>subst O: C:\TestDir
C:\>mv testfile_hl O:\testfile_hl
C:\>ls -l testfile
-rwxrwxrwx 1 R.+Vittal None 0 Jul 31 13:35
testfile (link count here is 1)
</command line>
Executing the following code: (There is no reduction in link count)
<Result>
linkcount1 2
linkcount2 2
BasicFileAttributs are same after moving hardlink
</Result>
<code>
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class MoveHardLink {
public static void main(String... args) {
Path path = null;
Path targetDir = null;
Path hardLink = null;
Path target = null;
try {
path = Paths.get("c:\\testfile").createFile();
hardLink = Paths.get("testfile_hl").createLink(path);
int linkcount1 = Attributes.readBasicFileAttributes(path,
false).linkCount();
targetDir = Paths.get("O:\\TestDirectory").createDirectory();
target = targetDir.resolve(Paths.get("testfile_hl"));
target = hardLink.moveTo(target);
int linkcount2 = Attributes.readBasicFileAttributes(path,
false).linkCount();
System.out.println("linkcount1 " + linkcount1);
System.out.println("linkcount2 " + linkcount2);
boolean result = (linkcount1 == linkcount2);
if (result) {
System.out.println("BasicFileAttributs are same after
moving hardlink");
} else {
System.out.println("Basic File Atributes are not same
after moving hardlink");
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
try {
path.delete(true);
hardLink.delete(false);
target.delete(true);
targetDir.delete(true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
</Code>
thanks
Rajendra.
More information about the nio-dev
mailing list