Skip to content

Commit 49d5b12

Browse files
committed
Move isPathInside to utils.
1 parent d8c679f commit 49d5b12

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

lib/mayaUsd/utils/utilComponentCreator.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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-
228212
bool 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

lib/mayaUsd/utils/utilFileSystem.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

lib/mayaUsd/utils/utilFileSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ void pathRemoveExtension(std::string& filePath);
308308
MAYAUSD_CORE_PUBLIC
309309
std::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.
312317
class FileBackup
313318
{

0 commit comments

Comments
 (0)