@@ -227,26 +227,29 @@ pub fn collect_entries<P: AsRef<Path>, State>(
227227 for source in sources {
228228 let path = source. as_ref ( ) ;
229229
230- // `symlink_metadata` (lstat) is required here instead of `exists`/`metadata`
231- // (stat) so that a dangling symlink (target missing) is still treated as a
232- // present source; it is later classified as EntryType::Symlink below. The
233- // result is reused in the single-file branch to avoid a second lstat.
230+ // `symlink_metadata` (lstat) is required here instead of
231+ // `exists`/`metadata` (stat) so that a dangling symlink (target
232+ // missing) is still treated as a present source; it is later
233+ // classified as EntryType::Symlink below. The result is reused
234+ // in the single-file branch to avoid a second lstat.
234235 let Ok ( metadata) = path. symlink_metadata ( ) else {
235236 return Err ( ArchiveError :: SourceNotFound {
236237 path : path. to_path_buf ( ) ,
237238 } ) ;
238239 } ;
239240
240- // `metadata.is_dir()` (from the lstat above) is required here instead of
241- // `path.is_dir()` (stat, follows symlinks), so that a symlink pointing at a
242- // directory is not routed into `FilteredWalker`/`WalkDir` by default —
243- // `WalkDir` always dereferences its root regardless of `follow_links(false)`
244- // and would produce an empty relative path for the root entry. Such a symlink
245- // is instead classified as `EntryType::Symlink` in the branch below,
246- // consistent with the symlink-to-file case. When `follow_symlinks` is
247- // explicitly enabled, though, the symlink must still be walked as a directory
248- // (via `path.is_dir()`, stat) to preserve the pre-existing dereferencing
249- // behavior for that config — otherwise the single-entry branch would try to
241+ // `metadata.is_dir()` (from the lstat above) is required here instead
242+ // of `path.is_dir()` (stat, follows symlinks), so that a
243+ // symlink pointing at a directory is not routed into
244+ // `FilteredWalker`/`WalkDir` by default — `WalkDir` always
245+ // dereferences its root regardless of `follow_links(false)` and
246+ // would produce an empty relative path for the root entry. Such a
247+ // symlink is instead classified as `EntryType::Symlink` in the
248+ // branch below, consistent with the symlink-to-file case. When
249+ // `follow_symlinks` is explicitly enabled, though, the symlink
250+ // must still be walked as a directory (via `path.is_dir()`,
251+ // stat) to preserve the pre-existing dereferencing behavior for
252+ // that config — otherwise the single-entry branch would try to
250253 // open the symlink as a regular file and fail with an I/O error.
251254 if metadata. is_dir ( ) || ( config. follow_symlinks && path. is_dir ( ) ) {
252255 let walker = FilteredWalker :: new ( path, config) ;
@@ -255,11 +258,13 @@ pub fn collect_entries<P: AsRef<Path>, State>(
255258 }
256259 } else {
257260 // For single files, we need to create a FilteredEntry manually.
258- // `symlink_metadata` (lstat) is required here instead of `metadata` (stat)
259- // so that a symlink passed directly as a top-level source is classified as
260- // EntryType::Symlink rather than silently dereferenced into its target.
261- // `metadata.is_dir()` can no longer be true here (that case is routed to
262- // the walk branch above), so only `File` and `Symlink` remain.
261+ // `symlink_metadata` (lstat) is required here instead of `metadata`
262+ // (stat) so that a symlink passed directly as a
263+ // top-level source is classified as EntryType::Symlink
264+ // rather than silently dereferenced into its target.
265+ // `metadata.is_dir()` can no longer be true here (that case is
266+ // routed to the walk branch above), so only `File` and
267+ // `Symlink` remain.
263268 let size = if metadata. is_file ( ) {
264269 metadata. len ( )
265270 } else {
@@ -336,7 +341,8 @@ mod tests {
336341 let walker = FilteredWalker :: new ( root, & config) ;
337342 let entries: Vec < _ > = walker. walk ( ) . collect :: < Result < Vec < _ > > > ( ) . unwrap ( ) ;
338343
339- // Should find exactly: root dir, file1, file2, subdir, file3 = 5 entries
344+ // Should find exactly: root dir, file1, file2, subdir, file3 = 5
345+ // entries
340346 assert_eq ! ( entries. len( ) , 5 , "expected exactly 5 entries" ) ;
341347
342348 let paths: Vec < _ > = entries
@@ -657,8 +663,8 @@ mod tests {
657663
658664 let entries = collect_entries ( & sources, & config) . unwrap ( ) ;
659665
660- // Should have: single_file.txt (1) + dir1 entries (2 files + 1 dir = 3) + dir2
661- // entries (1 file + 1 dir = 2) = 6 total
666+ // Should have: single_file.txt (1) + dir1 entries (2 files + 1 dir = 3)
667+ // + dir2 entries (1 file + 1 dir = 2) = 6 total
662668 assert ! (
663669 entries. len( ) >= 5 ,
664670 "Expected at least 5 entries (files and dirs), got {}" ,
@@ -699,8 +705,8 @@ mod tests {
699705
700706 let entries = collect_entries ( & sources, & config) . unwrap ( ) ;
701707
702- // Should have: 50 files in root + 1 subdir + 1 root dir + 30 files in subdir =
703- // 82
708+ // Should have: 50 files in root + 1 subdir + 1 root dir + 30 files in
709+ // subdir = 82
704710 assert ! (
705711 entries. len( ) >= 80 ,
706712 "Expected at least 80 entries, got {}" ,
0 commit comments