-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: native copy-on-write support
- Loading branch information
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/keuin/kbackupfabric/util/cow/FileCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.keuin.kbackupfabric.util.cow; | ||
|
||
import java.io.IOException; | ||
|
||
public interface FileCopier { | ||
void copy(String dst, String src) throws IOException; | ||
|
||
boolean isCow(); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.keuin.kbackupfabric.util.cow; | ||
|
||
import com.keuin.kbackupfabric.util.PrintUtil; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public final class FileCowCopier { | ||
private static final AtomicBoolean initialized = new AtomicBoolean(false); | ||
|
||
static { | ||
try { | ||
System.loadLibrary("kbackup_cow"); | ||
} catch (SecurityException | UnsatisfiedLinkError ignored) { | ||
} | ||
} | ||
|
||
public static native void init(); | ||
|
||
public static native void copy(String dst, String src) throws IOException; | ||
|
||
public static native String getVersion(); | ||
|
||
public static FileCopier getInstance() { | ||
if (initialized.compareAndSet(false, true)) { | ||
FileCowCopier.init(); | ||
PrintUtil.info("kbackup-cow version: " + FileCowCopier.getVersion()); | ||
} | ||
return new FileCopier() { | ||
@Override | ||
public void copy(String dst, String src) throws IOException { | ||
FileCowCopier.copy(dst, src); | ||
} | ||
|
||
@Override | ||
public boolean isCow() { | ||
return true; | ||
} | ||
}; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/keuin/kbackupfabric/util/cow/FileEagerCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.keuin.kbackupfabric.util.cow; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class FileEagerCopier implements FileCopier { | ||
@Override | ||
public void copy(String dst, String src) throws IOException { | ||
Files.copy(Paths.get(src), Paths.get(dst)); | ||
} | ||
|
||
@Override | ||
public boolean isCow() { | ||
return false; | ||
} | ||
} |