-
Notifications
You must be signed in to change notification settings - Fork 150
[hermes] Add shadow copy creation #3006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Gb7f1abf97eed8a035dbcaf7b0363b5890baaec05
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| use std::{ | ||||||
| collections::HashSet, | ||||||
| fs, | ||||||
| path::{Path, PathBuf}, | ||||||
| }; | ||||||
|
|
||||||
| use anyhow::{Context, Result}; | ||||||
| use walkdir::WalkDir; | ||||||
|
|
||||||
| // TODO: Call this with `skip_paths` set to all `.rs` files which we've found | ||||||
| // via our traversal using syn. | ||||||
|
|
||||||
| /// Creates a "Shadow Skeleton" of the source project. | ||||||
| pub fn create_shadow_skeleton( | ||||||
| source_root: &Path, | ||||||
| dest_root: &Path, | ||||||
| target_dir: &Path, | ||||||
| skip_paths: &HashSet<PathBuf>, | ||||||
| ) -> Result<()> { | ||||||
| let walker = WalkDir::new(source_root) | ||||||
| .follow_links(false) // Security: don't follow symlinks out of the root. | ||||||
| .into_iter(); | ||||||
|
|
||||||
| for entry in walker.filter_entry(|e| e.path() != target_dir && e.file_name() != ".git") { | ||||||
| let entry = entry.context("Failed to read directory entry")?; | ||||||
| let src_path = entry.path(); | ||||||
|
|
||||||
| let relative_path = | ||||||
| src_path.strip_prefix(source_root).context("File is not inside source root")?; | ||||||
| let dest_path = dest_root.join(relative_path); | ||||||
|
|
||||||
| if entry.file_type().is_dir() { | ||||||
| fs::create_dir_all(&dest_path) | ||||||
| .with_context(|| format!("Failed to create shadow directory: {:?}", dest_path))?; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve the readability of error messages, consider using
Suggested change
|
||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
| if entry.file_type().is_file() && !skip_paths.contains(src_path) { | ||||||
| make_symlink(src_path, &dest_path)?; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| #[cfg(unix)] | ||||||
| fn make_symlink(original: &Path, link: &Path) -> Result<()> { | ||||||
| std::os::unix::fs::symlink(original, link) | ||||||
| .with_context(|| format!("Failed to symlink {:?} -> {:?}", original, link)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For cleaner and more user-friendly error messages, it's preferable to use
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| #[cfg(windows)] | ||||||
| fn make_symlink(original: &Path, link: &Path) -> Result<()> { | ||||||
| // Windows treats file and directory symlinks differently. | ||||||
| // Since we only call this on files (checking is_file above), | ||||||
| // we use symlink_file. | ||||||
| std::os::windows::fs::symlink_file(original, link) | ||||||
| .with_context(|| format!("Failed to symlink {:?} -> {:?}", original, link)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve the readability of error messages, consider using
Suggested change
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"files":{".cargo_vcs_info.json":"6dd5cd03c25ddfc57cd9bd43fcd964b24fecb903f60fd1568f092121b22fee93","COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.lock":"fa40407b035c7abffe97d267d2ff95d22d83e5b916aca876bec49a56a9067c73","Cargo.toml":"991f8df8fa5a259801900a56908cf21a66c5cf7b238bc81ba9bdf348e233252e","Cargo.toml.orig":"d0b19f99d598bf88dd101f441f577d7a82455cf85d1f44aa0771e1d1f633da45","LICENSE-MIT":"cb3c929a05e6cbc9de9ab06a4c57eeb60ca8c724bef6c138c87d3a577e27aa14","README.md":"70c109d9c89b4479016142f2a4ad6963b6fe5793bcdd997add3d3af3d2baf36b","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","examples/is_same_file.rs":"7b3eeb27a15051667d97615fc7a2339cbff5630df3bca6ac19ab81d5be22f329","examples/is_stderr.rs":"e1c5d1a0f36d7aa0020bb5b87c2f45c7176033f03c52cf395be55dd8debfc413","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/lib.rs":"b22c2f0b5cad2248f16f4f42add52b2dc0c627631f71ee67a8c38fe305048f85","src/unix.rs":"69abed9fade151247696c6d4a442ef299554f3722e23a2d08053598a52a27d62","src/unknown.rs":"bfde4e9ac88f500c0ccb69165383682ddd24bf7d7ddaf5859426e1fd4b2f9359","src/win.rs":"94f912cc3734f60608d0ee2b0c664afb65fc96e5b0b223a53565fb8998c03fa3"},"package":"93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "git": { | ||
| "sha1": "5799cd323b8eefd17a089c950dac113f66c89c9e" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| This project is dual-licensed under the Unlicense and MIT licenses. | ||
|
|
||
| You may use this code under the terms of either license. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| # | ||
| # When uploading crates to the registry Cargo will automatically | ||
| # "normalize" Cargo.toml files for maximal compatibility | ||
| # with all versions of Cargo and also rewrite `path` dependencies | ||
| # to registry (e.g., crates.io) dependencies | ||
| # | ||
| # If you believe there's an error in this file please file an | ||
| # issue against the rust-lang/cargo repository. If you're | ||
| # editing this file be aware that the upstream Cargo.toml | ||
| # will likely look very different (and much more reasonable) | ||
|
|
||
| [package] | ||
| edition = "2018" | ||
| name = "same-file" | ||
| version = "1.0.6" | ||
| authors = ["Andrew Gallant <jamslam@gmail.com>"] | ||
| exclude = ["/.github"] | ||
| description = "A simple crate for determining whether two file paths point to the same file.\n" | ||
| homepage = "https://github.com/BurntSushi/same-file" | ||
| documentation = "https://docs.rs/same-file" | ||
| readme = "README.md" | ||
| keywords = ["same", "file", "equal", "inode"] | ||
| license = "Unlicense/MIT" | ||
| repository = "https://github.com/BurntSushi/same-file" | ||
| [dev-dependencies.doc-comment] | ||
| version = "0.3" | ||
| [target."cfg(windows)".dependencies.winapi-util] | ||
| version = "0.1.1" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2017 Andrew Gallant | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For more user-friendly error messages, it's better to use
.display()for printing paths instead of theDebugformat ({:?}). TheDebugformat forPathincludes quotes, which can make the output less clean for users.