Skip to content

Commit 2c90f0c

Browse files
committed
fix: try to ignore earlier to avoid any attempt to access a file or read its metadata without permission if we were trying to ignore said file.
1 parent 40dae1a commit 2c90f0c

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

migration/util/node-types/src/executor/movement_executor.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,39 @@ fn copy_dir_recursive_with_ignore(src: &Path, ignore_paths: impl IntoIterator<It
3939
let ignore_paths: Vec<_> = ignore_paths.into_iter().collect();
4040
let mut errors: Vec<Result<(), anyhow::Error>> = Vec::new();
4141

42-
for entry in WalkDir::new(src) {
42+
// Configure WalkDir to be more resilient
43+
let walker = WalkDir::new(src)
44+
.follow_links(false)
45+
.same_file_system(true)
46+
.into_iter()
47+
.filter_entry(|entry| {
48+
// Early filter for ignored paths to avoid permission errors
49+
let path = entry.path();
50+
!ignore_paths.iter().any(|ignore| path.to_string_lossy().contains(ignore.as_ref().to_string_lossy().as_ref()))
51+
});
52+
53+
for entry in walker {
4354
let entry = match entry {
4455
Ok(e) => e,
4556
Err(e) => {
46-
errors.push(Err(e.into()));
57+
// Check if this is a permission error on an ignored path
58+
if let Some(path) = e.path() {
59+
if ignore_paths.iter().any(|ignore| path.to_string_lossy().contains(ignore.as_ref().to_string_lossy().as_ref())) {
60+
debug!("Ignoring permission error on ignored path: {}", path.display());
61+
continue;
62+
}
63+
}
64+
// For other errors, log with info for now and fail.
65+
info!("Error accessing path: {:?}", e);
66+
errors.push(Err(anyhow::anyhow!("failed to get entry: {:?}", e)));
4767
continue;
4868
}
4969
};
5070

5171
debug!("Processing entry: {}", entry.path().display());
5272

5373
let path = entry.path();
54-
55-
// Skip if path matches any ignore pattern
56-
if ignore_paths.iter().any(|ignore| path.to_string_lossy().contains(ignore.as_ref().to_string_lossy().as_ref())) {
57-
debug!("skipping ignored path: {}", path.display());
58-
continue;
59-
}
60-
61-
// Make the path relative to src
62-
let rel_path = match path.strip_prefix(src) {
63-
Ok(p) => p,
64-
Err(e) => {
65-
errors.push(Err(e.into()));
66-
continue;
67-
}
68-
};
69-
70-
let dest_path = dst.join(rel_path);
74+
let dest_path = dst.join(path.strip_prefix(src).context("failed to strip prefix")?);
7175

7276
if entry.file_type().is_dir() {
7377
match fs::create_dir_all(&dest_path) {
@@ -510,6 +514,7 @@ mod test {
510514
}
511515

512516
// Somehow the following test is failing on CI: https://github.com/movementlabsxyz/movement-migration/actions/runs/15386989846/job/43287594343
517+
// This indicates that failure is not due to the inability to ignore copy, but rather some issue performing an oepration that requires permissions.
513518
#[test]
514519
fn test_are_you_kidding_me() -> Result<(), anyhow::Error> {
515520

@@ -519,7 +524,11 @@ mod test {
519524
let path_that_must_be_ignored = source_dir.path().join(".movement/celestia/c1860ae680eb2d91927b/.celestia-app/keyring-test");
520525

521526
fs::create_dir_all(path_that_must_be_ignored.parent().context("failed to get parent directory for path that must be ignored")?).context("failed to create directory")?;
522-
fs::write(path_that_must_be_ignored, "test").context("failed to write file that must not be ignored")?;
527+
// write a file that must not be ignored
528+
fs::write(path_that_must_be_ignored.clone(), "test").context("failed to write file that must not be ignored")?;
529+
// set permissions to 000 on the file and then on the parent directory
530+
fs::set_permissions(path_that_must_be_ignored.clone(), Permissions::from_mode(0o000)).context("failed to set permissions on file that must not be ignored")?;
531+
fs::set_permissions(path_that_must_be_ignored.parent().context("failed to get parent directory for path that must be ignored")?, Permissions::from_mode(0o000)).context("failed to set permissions on parent directory that must not be ignored")?;
523532

524533
copy_dir_recursive_with_ignore(source_dir.path(), ["celestia"], target_dir.path()).context("failed to copy directory")?;
525534

0 commit comments

Comments
 (0)