diff options
author | Keuin <[email protected]> | 2024-01-20 13:20:41 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2024-01-20 13:51:41 +0800 |
commit | 7e3cd92742383c43f2741449c551208e6487154e (patch) | |
tree | f6a4a51d0164231ac0fd2faed8f313aa504e2504 /src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java | |
parent | 61aa66b558ae8f2987a238216ac01e375f195c1e (diff) |
feature: configurable CoW incremental backup
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java b/src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java new file mode 100644 index 0000000..e5819de --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/util/cow/FileCowCopier.java @@ -0,0 +1,44 @@ +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()); + } + // call a native method to ensure the dynamic library is correctly loaded, JVM will throw if failed + // so the outside fallback logic could work + 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; + } + }; + } +} |