commit
51672f3705
@ -0,0 +1 @@ |
|||||||
|
/target |
@ -0,0 +1,117 @@ |
|||||||
|
# This file is automatically @generated by Cargo. |
||||||
|
# It is not intended for manual editing. |
||||||
|
version = 3 |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "async-recursion" |
||||||
|
version = "0.3.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "d7d78656ba01f1b93024b7c3a0467f1608e4be67d725749fdcd7d2c7678fd7a2" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"syn", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "autocfg" |
||||||
|
version = "1.0.1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "dfm" |
||||||
|
version = "0.1.0" |
||||||
|
dependencies = [ |
||||||
|
"async-recursion", |
||||||
|
"tokio", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "hermit-abi" |
||||||
|
version = "0.1.19" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" |
||||||
|
dependencies = [ |
||||||
|
"libc", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "libc" |
||||||
|
version = "0.2.100" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "a1fa8cddc8fbbee11227ef194b5317ed014b8acbf15139bd716a18ad3fe99ec5" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "num_cpus" |
||||||
|
version = "1.13.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" |
||||||
|
dependencies = [ |
||||||
|
"hermit-abi", |
||||||
|
"libc", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "pin-project-lite" |
||||||
|
version = "0.2.7" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "proc-macro2" |
||||||
|
version = "1.0.28" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" |
||||||
|
dependencies = [ |
||||||
|
"unicode-xid", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "quote" |
||||||
|
version = "1.0.9" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "syn" |
||||||
|
version = "1.0.75" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"unicode-xid", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "tokio" |
||||||
|
version = "1.10.1" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "92036be488bb6594459f2e03b60e42df6f937fe6ca5c5ffdcb539c6b84dc40f5" |
||||||
|
dependencies = [ |
||||||
|
"autocfg", |
||||||
|
"num_cpus", |
||||||
|
"pin-project-lite", |
||||||
|
"tokio-macros", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "tokio-macros" |
||||||
|
version = "1.3.0" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" |
||||||
|
dependencies = [ |
||||||
|
"proc-macro2", |
||||||
|
"quote", |
||||||
|
"syn", |
||||||
|
] |
||||||
|
|
||||||
|
[[package]] |
||||||
|
name = "unicode-xid" |
||||||
|
version = "0.2.2" |
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||||
|
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" |
@ -0,0 +1,13 @@ |
|||||||
|
[package] |
||||||
|
name = "dfm" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2018" |
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[profile.release] |
||||||
|
lto = true |
||||||
|
codegen-units = 1 |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
async-recursion = "0.3" |
||||||
|
tokio = { version = "1.10", features = ["fs", "macros", "rt-multi-thread"] } |
@ -0,0 +1,47 @@ |
|||||||
|
use async_recursion::async_recursion; |
||||||
|
use tokio::fs; |
||||||
|
|
||||||
|
#[tokio::main] |
||||||
|
async fn main() -> std::io::Result<()> { |
||||||
|
let home_dir = std::env::var("HOME").expect("Could not get home dir"); |
||||||
|
symlink_folder(&format!("{}/.df", home_dir), &home_dir).await; |
||||||
|
Ok(()) |
||||||
|
} |
||||||
|
|
||||||
|
#[async_recursion] |
||||||
|
async fn symlink_folder(src_dir: &str, target_dir: &str) { |
||||||
|
fs::create_dir_all(target_dir) |
||||||
|
.await |
||||||
|
.expect(&format!("Could not create {}", target_dir)); |
||||||
|
let mut dir_contents = fs::read_dir(src_dir) |
||||||
|
.await |
||||||
|
.expect(&format!("Could read dir {}", src_dir)); |
||||||
|
while let Ok(Some(entry)) = dir_contents.next_entry().await { |
||||||
|
let os_name = entry.file_name(); |
||||||
|
let name = os_name.to_str().unwrap(); |
||||||
|
if name == ".git" { |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
if let Ok(metadata) = entry.metadata().await { |
||||||
|
if metadata.is_dir() { |
||||||
|
symlink_folder( |
||||||
|
&format!("{}/{}", src_dir, name), |
||||||
|
&format!("{}/{}", target_dir, name), |
||||||
|
) |
||||||
|
.await; |
||||||
|
} |
||||||
|
|
||||||
|
if metadata.is_file() { |
||||||
|
#[allow(unused_must_use)] |
||||||
|
let _ = fs::remove_file(&format!("{}/{}", target_dir, name)).await; |
||||||
|
fs::symlink( |
||||||
|
&format!("{}/{}", src_dir, name), |
||||||
|
&format!("{}/{}", target_dir, name), |
||||||
|
) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue