@@ -44,7 +44,7 @@ impl DirectoryListing {
4444 match self . file_type ( name) {
4545 Some ( FileType :: Directory ) => true ,
4646 Some ( FileType :: File ) | None => false ,
47- Some ( FileType :: Symlink ) => db . system ( ) . is_directory ( & directory. join ( name) ) ,
47+ Some ( FileType :: Symlink ) => system_path_to_directory ( db , directory. join ( name) ) . is_ok ( ) ,
4848 }
4949 }
5050
@@ -140,6 +140,49 @@ mod tests {
140140 use crate :: system:: { DbWithWritableSystem as _, SystemPath } ;
141141 use crate :: tests:: TestDb ;
142142
143+ #[ test]
144+ #[ cfg( all( unix, feature = "os" ) ) ]
145+ fn symlink_target_changes_without_parent_listing_change ( ) -> std:: io:: Result < ( ) > {
146+ use super :: system_path_to_directory;
147+ use crate :: Db ;
148+ use crate :: files:: { File , FilePath } ;
149+ use crate :: system:: { DbWithTestSystem as _, OsSystem } ;
150+
151+ #[ salsa:: tracked]
152+ fn linked_directory_exists ( db : & dyn Db , directory : File ) -> bool {
153+ let FilePath :: System ( path) = directory. path ( db) else {
154+ return false ;
155+ } ;
156+ directory_listing ( db, path)
157+ . is_ok_and ( |listing| listing. entry_is_directory ( db, path, "link" ) )
158+ }
159+
160+ let temp_dir = tempfile:: tempdir ( ) ?;
161+ let root = SystemPath :: from_std_path ( temp_dir. path ( ) )
162+ . ok_or_else ( || std:: io:: Error :: other ( "temporary directory is not UTF-8" ) ) ?;
163+ let directory = root. join ( "src" ) ;
164+ let target = root. join ( "target" ) ;
165+ let link = directory. join ( "link" ) ;
166+
167+ let mut db = TestDb :: new ( ) ;
168+ db. use_system ( OsSystem :: new ( root) ) ;
169+ std:: fs:: create_dir ( directory. as_std_path ( ) ) ?;
170+ std:: os:: unix:: fs:: symlink ( target. as_std_path ( ) , link. as_std_path ( ) ) ?;
171+
172+ let directory_file =
173+ system_path_to_directory ( & db, & directory) . map_err ( std:: io:: Error :: other) ?;
174+
175+ assert ! ( !linked_directory_exists( & db, directory_file) ) ;
176+
177+ std:: fs:: create_dir ( target. as_std_path ( ) ) ?;
178+ // The link's target changed, but the directory containing the link did not.
179+ File :: sync_path ( & mut db, & link) ;
180+
181+ assert ! ( linked_directory_exists( & db, directory_file) ) ;
182+
183+ Ok ( ( ) )
184+ }
185+
143186 #[ test]
144187 fn listing_is_sorted ( ) -> std:: io:: Result < ( ) > {
145188 let mut db = TestDb :: new ( ) ;
0 commit comments