From fd9c8e9fec6483e208764fbc5a11f4875080e1f4 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Thu, 21 Nov 2024 23:43:29 +0700 Subject: [PATCH 01/13] chore: remove rustfmt.toml as it is incorrect --- rustfmt.toml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index cab5731..0000000 --- a/rustfmt.toml +++ /dev/null @@ -1,2 +0,0 @@ -tab_spaces = 2 -edition = "2021" From 902ac682958af558ccf5ce808a6659183f00fc46 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Thu, 21 Nov 2024 23:52:23 +0700 Subject: [PATCH 02/13] refactor: fix format --- src/lib.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 053f774..8c678b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,14 +17,11 @@ impl Task for AsyncReflink { fn compute(&mut self) -> Result { match reflink_file_sync(&self.src, &self.dst) { - Ok(_) => { - Ok(()) - }, - Err(err) => return Err(Error::from_reason(format!( - "{}, reflink '{}' -> '{}'", - err.to_string(), - self.src, - self.dst + Ok(_) => Ok(()), + Err(err) => Err(Error::from_reason(format!( + "{err}, reflink '{src}' -> '{dst}'", + src = self.src, + dst = self.dst, ))), } } @@ -46,10 +43,7 @@ pub fn reflink_sync(env: Env, src: String, dst: String) -> Result { match reflink_file_sync(&src, &dst) { Ok(_) => Ok(env.create_int32(0)?), Err(err) => Err(Error::from_reason(format!( - "{}, reflink '{}' -> '{}'", - err.to_string(), - src, - dst + "{err}, reflink '{src}' -> '{dst}'" ))), } } @@ -63,7 +57,7 @@ pub fn test_pyc_file() { // Remove the destination file if it already exists if dst_path.try_exists().unwrap() { - std::fs::remove_file(&dst).unwrap(); + std::fs::remove_file(dst).unwrap(); } // Run the reflink operation @@ -73,13 +67,13 @@ pub fn test_pyc_file() { println!("Reflinked {src:?} -> {dst:?}"); // Further validation: compare the contents of both files to make sure they are identical - let src_contents = std::fs::read(&src).expect("Failed to read source file"); - let dst_contents = std::fs::read(&dst).expect("Failed to read destination file"); + let src_contents = std::fs::read(src).expect("Failed to read source file"); + let dst_contents = std::fs::read(dst).expect("Failed to read destination file"); assert_eq!(src_contents, dst_contents); // Remove the destination file - std::fs::remove_file(&dst).unwrap(); + std::fs::remove_file(dst).unwrap(); println!("File contents match, reflink operation successful") -} \ No newline at end of file +} From b6188085573db3eb6b6094dfc4546a2b7bc8d569 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Thu, 21 Nov 2024 23:54:20 +0700 Subject: [PATCH 03/13] chore: upgrade rust-toolchain --- rust-toolchain | 1 + 1 file changed, 1 insertion(+) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..71fae54 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +1.82.0 From bd2d5e36425992886036c45fb297d306f0a36b25 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Thu, 21 Nov 2024 23:56:23 +0700 Subject: [PATCH 04/13] chore: update dependencies --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04b0873..6ed8ec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,13 +8,13 @@ crate-type = ["cdylib"] [dependencies] copy_on_write = "0.1.3" -futures = "0.3.28" +futures = "0.3.31" # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix -napi = { version = "2.12.2", default-features = false, features = ["napi4"] } -napi-derive = "2.12.2" +napi = { version = "2.16.13", default-features = false, features = ["napi4"] } +napi-derive = "2.16.12" [build-dependencies] -napi-build = "2.0.1" +napi-build = "2.1.3" [profile.release] lto = true From bc381af60068f5782abce3ad7f0896995345a4ee Mon Sep 17 00:00:00 2001 From: khai96_ Date: Thu, 21 Nov 2024 23:56:55 +0700 Subject: [PATCH 05/13] chore(git): add Cargo.lock --- .gitignore | 5 +- Cargo.lock | 635 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 637 insertions(+), 3 deletions(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 761607e..1147f61 100644 --- a/.gitignore +++ b/.gitignore @@ -121,7 +121,7 @@ dist .AppleDouble .LSOverride -# Icon must end with two +# Icon must end with two Icon @@ -184,7 +184,6 @@ $RECYCLE.BIN/ #Added by cargo /target -Cargo.lock .pnp.* .yarn/* @@ -201,4 +200,4 @@ Cargo.lock sandbox __reflink-tests-* -*.json.bak \ No newline at end of file +*.json.bak diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..92ec0c1 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,635 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "copy_on_write" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "231be9abfd4fd31196f0e2ba13b314391969131530e14d84d2b9e954ff27d509" +dependencies = [ + "env_logger", + "lazy_static", + "log", + "reflink-copy", + "tempfile", + "widestring", + "windows", +] + +[[package]] +name = "ctor" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" + +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets 0.52.6", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "napi" +version = "2.16.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "214f07a80874bb96a8433b3cdfc84980d56c7b02e1a0d7ba4ba0db5cef785e2b" +dependencies = [ + "bitflags", + "ctor", + "napi-derive", + "napi-sys", + "once_cell", +] + +[[package]] +name = "napi-build" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1c0f5d67ee408a4685b61f5ab7e58605c8ae3f2b4189f0127d804ff13d5560a" + +[[package]] +name = "napi-derive" +version = "2.16.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17435f7a00bfdab20b0c27d9c56f58f6499e418252253081bfff448099da31d1" +dependencies = [ + "cfg-if", + "convert_case", + "napi-derive-backend", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "napi-derive-backend" +version = "1.0.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "967c485e00f0bf3b1bdbe510a38a4606919cf1d34d9a37ad41f25a81aa077abe" +dependencies = [ + "convert_case", + "once_cell", + "proc-macro2", + "quote", + "regex", + "semver", + "syn", +] + +[[package]] +name = "napi-sys" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427802e8ec3a734331fec1035594a210ce1ff4dc5bc1950530920ab717964ea3" +dependencies = [ + "libloading", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "reflink" +version = "0.0.0" +dependencies = [ + "copy_on_write", + "futures", + "napi", + "napi-build", + "napi-derive", +] + +[[package]] +name = "reflink-copy" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f97f7665e51f23760e9e4949d454a4782c76ef954acaeec9d1b0f48a58e4529e" +dependencies = [ + "cfg-if", + "rustix", + "windows", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustix" +version = "0.38.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "widestring" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +dependencies = [ + "windows-core", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" From 3beb6074bf19fa1d598c6841d408dab1979e45ae Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 08:10:37 +0700 Subject: [PATCH 06/13] chore: don't force editor customization --- .gitignore | 2 ++ .vscode/{extensions.json => extensions.json.template} | 0 .vscode/{settings.json => settings.json.template} | 0 3 files changed, 2 insertions(+) rename .vscode/{extensions.json => extensions.json.template} (100%) rename .vscode/{settings.json => settings.json.template} (100%) diff --git a/.gitignore b/.gitignore index 1147f61..edfcccd 100644 --- a/.gitignore +++ b/.gitignore @@ -201,3 +201,5 @@ $RECYCLE.BIN/ sandbox __reflink-tests-* *.json.bak + +/.vscode/*.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json.template similarity index 100% rename from .vscode/extensions.json rename to .vscode/extensions.json.template diff --git a/.vscode/settings.json b/.vscode/settings.json.template similarity index 100% rename from .vscode/settings.json rename to .vscode/settings.json.template From d75c44e23dac9d3373e932de2f96b0e25a8c7db0 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 08:11:30 +0700 Subject: [PATCH 07/13] ci: fix --- .github/workflows/CI.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 899a663..b804ea9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,6 +40,7 @@ jobs: docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian build: |- set -e && + rustup target add x86_64-unknown-linux-gnu && pnpm build --target x86_64-unknown-linux-gnu && strip *.node - host: ubuntu-latest @@ -56,6 +57,7 @@ jobs: docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 build: |- set -e && + rustup target add aarch64-unknown-linux-gnu && pnpm build --target aarch64-unknown-linux-gnu && aarch64-unknown-linux-gnu-strip *.node - host: ubuntu-latest @@ -64,6 +66,7 @@ jobs: build: |- set -e && rustup target add aarch64-unknown-linux-musl && + rustup target add aarch64-unknown-linux-musl && pnpm build --target aarch64-unknown-linux-musl && /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node - host: windows-latest @@ -257,7 +260,7 @@ jobs: version: 8.10.2 run_install: false standalone: true - + - name: Install dependencies run: | pnpm dlx @ialdama/jsonmod --key pnpm.supportedArchitectures.libc --values musl current @@ -334,7 +337,7 @@ jobs: with: name: bindings-aarch64-unknown-linux-musl path: . - + - name: Setup pnpm uses: pnpm/action-setup@v2 with: @@ -410,7 +413,7 @@ jobs: COMMIT_MESSAGE=$(git log -1 --pretty=%B) fi RELEASE_TYPE=$(echo $COMMIT_MESSAGE | grep -oE "\(([a-zA-Z]+)\)" | tr -d '()') - + if [ "${GITHUB_REF##*/}" = "main" ]; then if [[ $COMMIT_MESSAGE =~ ^release(\ \([a-zA-Z]+\))?:\ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then # Use a default release type of 'latest' if no type is specified in the commit message @@ -424,23 +427,23 @@ jobs: if [[ $COMMIT_MESSAGE =~ ^release(\ \([a-zA-Z]+\))?:\ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then # Use a default release type of 'canary' if no type is specified in the commit message RELEASE_TYPE=${RELEASE_TYPE:-canary} - + # Extract the current version from package.json CURRENT_VERSION=$(jq -r '.version' package.json) - + # Create a new pre-release version by appending the commit hash to the current version NEW_VERSION="$CURRENT_VERSION-canary.$COMMIT_HASH" - + # Update package.json with the new version jq --arg newVersion "$NEW_VERSION" '.version = $newVersion' package.json > temp.json && mv temp.json package.json - + echo "Updated version to $NEW_VERSION" pnpm run version - + # Set up .npmrc config file for authentication echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc - + # Publish the package with the new canary version npm publish --tag $RELEASE_TYPE --access public else @@ -452,6 +455,3 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - From 9defb0f86754e6f817c5075563ef0369d7b572dc Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 08:29:18 +0700 Subject: [PATCH 08/13] ci: fix --- .github/workflows/CI.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b804ea9..17eb017 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -66,12 +66,14 @@ jobs: build: |- set -e && rustup target add aarch64-unknown-linux-musl && - rustup target add aarch64-unknown-linux-musl && pnpm build --target aarch64-unknown-linux-musl && /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node - host: windows-latest target: aarch64-pc-windows-msvc - build: pnpm build --target aarch64-pc-windows-msvc + build: |- + set -e && + rustup target add aarch64-pc-windows-msvc && + pnpm build --target aarch64-pc-windows-msvc name: stable - ${{ matrix.settings.target }} - node@18 runs-on: ${{ matrix.settings.host }} steps: From 15b3db9646041c2c87cd4ea3e9c64f2fe446105e Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 08:41:10 +0700 Subject: [PATCH 09/13] chore(typescript): regenerate index.d.ts --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 27ae4c3..ecc4b08 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,5 +3,5 @@ /* auto-generated by NAPI-RS */ -export function reflinkFile(src: string, dst: string): Promise -export function reflinkFileSync(src: string, dst: string): number +export declare function reflinkFile(src: string, dst: string): Promise +export declare function reflinkFileSync(src: string, dst: string): number From b684752eb9e19bfcf919a13b444a588f59834a0a Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 08:44:42 +0700 Subject: [PATCH 10/13] refactor: prefer `map_err` --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8c678b5..c791f35 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,14 +16,13 @@ impl Task for AsyncReflink { type JsValue = JsNumber; fn compute(&mut self) -> Result { - match reflink_file_sync(&self.src, &self.dst) { - Ok(_) => Ok(()), - Err(err) => Err(Error::from_reason(format!( + reflink_file_sync(&self.src, &self.dst).map_err(|err| { + Error::from_reason(format!( "{err}, reflink '{src}' -> '{dst}'", src = self.src, dst = self.dst, - ))), - } + )) + }) } fn resolve(&mut self, env: Env, _: ()) -> Result { From 72cdf68d6714053e2e7838aac06376f739fb68e4 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 08:48:39 +0700 Subject: [PATCH 11/13] refactor: replace `extern crate` with `use` --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c791f35..efd6bd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,8 @@ #![deny(clippy::all)] -#[macro_use] -extern crate napi_derive; use copy_on_write::reflink_file_sync; use napi::{bindgen_prelude::AsyncTask, Env, Error, JsNumber, Result, Task}; +use napi_derive::napi; pub struct AsyncReflink { src: String, From 6ba40923b0e83bdc89c6e863a252beabcb4243c8 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 22 Nov 2024 10:16:27 +0700 Subject: [PATCH 12/13] test: fix failure case --- infinite_clone_test.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/infinite_clone_test.mjs b/infinite_clone_test.mjs index 040762e..6f833b9 100644 --- a/infinite_clone_test.mjs +++ b/infinite_clone_test.mjs @@ -61,4 +61,5 @@ function createHash(content) { main().catch((err) => { console.error(err); + throw process.exit(1); }); From e4c534b55a512232c14493cf17d38ba5097d2812 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 22 Nov 2024 09:35:22 +0100 Subject: [PATCH 13/13] Update infinite_clone_test.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- infinite_clone_test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infinite_clone_test.mjs b/infinite_clone_test.mjs index 6f833b9..dcb81d5 100644 --- a/infinite_clone_test.mjs +++ b/infinite_clone_test.mjs @@ -61,5 +61,5 @@ function createHash(content) { main().catch((err) => { console.error(err); - throw process.exit(1); + process.exit(1); });