Skip to content

Commit

Permalink
Use Files.createLink instead of shelling out to ln
Browse files Browse the repository at this point in the history
  • Loading branch information
ato committed Dec 3, 2024
1 parent 33556bf commit 4bb03ba
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/main/java/org/archive/io/ObjectPlusFilesOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
*/
package org.archive.io;

import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.*;
import java.nio.file.Files;
import java.util.LinkedList;

import org.archive.util.FileUtils;
Expand Down Expand Up @@ -116,19 +114,10 @@ public void snapshotAppendOnlyFile(File file) throws IOException {
* @throws IOException
*/
private void hardlinkOrCopy(File file, File destination) throws IOException {
// For Linux/UNIX, try a hard link first.
Process link = Runtime.getRuntime().exec("ln "+file.getAbsolutePath()+" "+destination.getAbsolutePath());
// TODO NTFS also supports hard links; add appropriate try
try {
link.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(link.exitValue()!=0) {
// hard link failed
Files.createLink(destination.toPath(), file.toPath());
} catch (UnsupportedEncodingException e) {
FileUtils.copyFile(file,destination);
}
}

}

0 comments on commit 4bb03ba

Please sign in to comment.