File tree Expand file tree Collapse file tree 3 files changed +25
-18
lines changed
Expand file tree Collapse file tree 3 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 1515//
1616
1717#include " util.h"
18+ #include " utilFileSystem.h"
1819
1920#include < mayaUsd/utils/utilComponentCreator.h>
2021
@@ -208,23 +209,6 @@ std::string moveAdskUsdComponent(
208209 return {};
209210}
210211
211- bool isPathInside (const std::string& parentDir, const std::string& childPath)
212- {
213- ghc::filesystem::path parent = ghc::filesystem::weakly_canonical (parentDir);
214- ghc::filesystem::path child = ghc::filesystem::weakly_canonical (childPath);
215-
216- // Iterate up from child to root
217- for (ghc::filesystem::path p = child; !p.empty (); p = p.parent_path ()) {
218- if (p == parent)
219- return true ;
220-
221- ghc::filesystem::path next = p.parent_path ();
222- if (next == p) // reached root (ex "C:\")
223- break ;
224- }
225- return false ;
226- }
227-
228212bool shouldDisplayComponentInitialSaveDialog (
229213 const pxr::UsdStageRefPtr stage,
230214 const std::string& proxyShapePath)
@@ -235,7 +219,8 @@ bool shouldDisplayComponentInitialSaveDialog(
235219
236220 MString tempDir;
237221 MGlobal::executeCommand (" internalVar -userTmpDir" , tempDir);
238- return isPathInside (UsdMayaUtil::convert (tempDir), stage->GetRootLayer ()->GetRealPath ());
222+ return UsdMayaUtilFileSystem::isPathInside (
223+ UsdMayaUtil::convert (tempDir), stage->GetRootLayer ()->GetRealPath ());
239224}
240225
241226} // namespace ComponentUtils
Original file line number Diff line number Diff line change @@ -803,3 +803,20 @@ void UsdMayaUtilFileSystem::FileBackup::restore()
803803 const std::string backupFileName = getBackupFilename ();
804804 rename (backupFileName.c_str (), _filename.c_str ());
805805}
806+
807+ bool UsdMayaUtilFileSystem::isPathInside (const std::string& parentDir, const std::string& childPath)
808+ {
809+ ghc::filesystem::path parent = ghc::filesystem::weakly_canonical (parentDir);
810+ ghc::filesystem::path child = ghc::filesystem::weakly_canonical (childPath);
811+
812+ // Iterate up from child to root
813+ for (ghc::filesystem::path p = child; !p.empty (); p = p.parent_path ()) {
814+ if (p == parent)
815+ return true ;
816+
817+ ghc::filesystem::path next = p.parent_path ();
818+ if (next == p) // reached root (ex "C:\")
819+ break ;
820+ }
821+ return false ;
822+ }
Original file line number Diff line number Diff line change @@ -308,6 +308,11 @@ void pathRemoveExtension(std::string& filePath);
308308MAYAUSD_CORE_PUBLIC
309309std::string pathFindExtension (std::string& filePath);
310310
311+ /* ! \brief returns true if the given child path is inside the given parent directory.
312+ */
313+ MAYAUSD_CORE_PUBLIC
314+ bool isPathInside (const std::string& parentDir, const std::string& childPath);
315+
311316// Backup a file and restore it if not committed.
312317class FileBackup
313318{
You can’t perform that action at this time.
0 commit comments