Skip to content

Commit ef8e862

Browse files
committed
Keep copy_tree from following dir symlinks
27 of the 28 replaced copiers checked entry.file_type(), which does not follow symlinks; only yarn_berry_common followed them. Following them lets a link cycle in an installed tree recurse until the stack overflows. The shared copy now checks file_type() like the majority. yarn_berry_common copies .socket and the yarn zip cache, which hold no directory links. The module doc no longer claims a re-export. Assisted-by: Claude Code:claude-opus-5-5
1 parent f81c50c commit ef8e862

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎crates/socket-patch-cli/tests/common/fs_tree.rs‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
//! Recursive directory copy for test fixtures. `common/mod.rs` re-exports
2-
//! it; shared modules whose includers don't all declare `mod common` pull
3-
//! this file in on its own with `#[path = "../common/fs_tree.rs"] mod
4-
//! fs_tree;`.
1+
//! Recursive directory copy for test fixtures, reached as
2+
//! `common::fs_tree::copy_tree`. Shared modules whose includers don't all
3+
//! declare `mod common` pull this file in on its own with
4+
//! `#[path = "../common/fs_tree.rs"] mod fs_tree;`.
55
66
#![allow(dead_code)]
77

88
use std::path::Path;
99

10-
/// Copy `src` into `dst`, creating `dst`. Symlinks are followed: a link to
11-
/// a directory is copied as a directory, a link to a file as the file.
12-
/// Panics if `src` is not a readable directory.
10+
/// Copy `src` into `dst`, creating `dst`. A symlink to a file is copied as
11+
/// the file; a symlink to a directory panics rather than being followed,
12+
/// so a link cycle in an installed tree can't recurse forever. Panics if
13+
/// `src` is not a readable directory.
1314
pub fn copy_tree(src: &Path, dst: &Path) {
1415
std::fs::create_dir_all(dst).unwrap();
1516
for entry in std::fs::read_dir(src).unwrap() {
1617
let entry = entry.unwrap();
1718
let to = dst.join(entry.file_name());
18-
if entry.path().is_dir() {
19+
if entry.file_type().unwrap().is_dir() {
1920
copy_tree(&entry.path(), &to);
2021
} else {
2122
std::fs::copy(entry.path(), &to).unwrap();

0 commit comments

Comments
 (0)