@@ -867,21 +867,16 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
867
867
// Any intermediate directories we create should be accessible by
868
868
// the owner, even if Perms says otherwise for the final path.
869
869
const auto NewDirectoryPerms = ResolvedPerms | sys::fs::owner_all;
870
+
871
+ StringRef Name = *I;
870
872
while (true ) {
871
- StringRef Name = *I;
872
- detail::InMemoryNode *Node = Dir->getChild (Name);
873
+ Name = *I;
873
874
++I;
875
+ if (I == E)
876
+ break ;
877
+ detail::InMemoryNode *Node = Dir->getChild (Name);
874
878
if (!Node) {
875
- if (I == E) {
876
- // End of the path.
877
- Dir->addChild (
878
- Name, MakeNode ({Dir->getUniqueID (), Path, Name, ModificationTime,
879
- std::move (Buffer), ResolvedUser, ResolvedGroup,
880
- ResolvedType, ResolvedPerms}));
881
- return true ;
882
- }
883
-
884
- // Create a new directory. Use the path up to here.
879
+ // This isn't the last element, so we create a new directory.
885
880
Status Stat (
886
881
StringRef (Path.str ().begin (), Name.end () - Path.str ().begin ()),
887
882
getDirectoryID (Dir->getUniqueID (), Name),
@@ -891,27 +886,33 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
891
886
Name, std::make_unique<detail::InMemoryDirectory>(std::move (Stat))));
892
887
continue ;
893
888
}
889
+ // Creating file under another file.
890
+ if (!isa<detail::InMemoryDirectory>(Node))
891
+ return false ;
892
+ Dir = cast<detail::InMemoryDirectory>(Node);
893
+ }
894
+ detail::InMemoryNode *Node = Dir->getChild (Name);
895
+ if (!Node) {
896
+ Dir->addChild (Name,
897
+ MakeNode ({Dir->getUniqueID (), Path, Name, ModificationTime,
898
+ std::move (Buffer), ResolvedUser, ResolvedGroup,
899
+ ResolvedType, ResolvedPerms}));
900
+ return true ;
901
+ }
902
+ if (isa<detail::InMemoryDirectory>(Node))
903
+ return ResolvedType == sys::fs::file_type::directory_file;
894
904
895
- if (auto *NewDir = dyn_cast<detail::InMemoryDirectory>(Node)) {
896
- Dir = NewDir;
897
- } else {
898
- assert ((isa<detail::InMemoryFile>(Node) ||
899
- isa<detail::InMemoryHardLink>(Node)) &&
900
- " Must be either file, hardlink or directory!" );
901
-
902
- // Trying to insert a directory in place of a file.
903
- if (I != E)
904
- return false ;
905
+ assert ((isa<detail::InMemoryFile>(Node) ||
906
+ isa<detail::InMemoryHardLink>(Node)) &&
907
+ " Must be either file, hardlink or directory!" );
905
908
906
- // Return false only if the new file is different from the existing one.
907
- if (auto Link = dyn_cast<detail::InMemoryHardLink>(Node)) {
908
- return Link->getResolvedFile ().getBuffer ()->getBuffer () ==
909
- Buffer->getBuffer ();
910
- }
911
- return cast<detail::InMemoryFile>(Node)->getBuffer ()->getBuffer () ==
912
- Buffer->getBuffer ();
913
- }
909
+ // Return false only if the new file is different from the existing one.
910
+ if (auto *Link = dyn_cast<detail::InMemoryHardLink>(Node)) {
911
+ return Link->getResolvedFile ().getBuffer ()->getBuffer () ==
912
+ Buffer->getBuffer ();
914
913
}
914
+ return cast<detail::InMemoryFile>(Node)->getBuffer ()->getBuffer () ==
915
+ Buffer->getBuffer ();
915
916
}
916
917
917
918
bool InMemoryFileSystem::addFile (const Twine &P, time_t ModificationTime,
0 commit comments