2022-03-22 09:50:26 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Common Functions and Definitions for Repo Commands
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#include "build.auto.h"
|
|
|
|
|
|
|
|
#include "command/repo/common.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "config/config.h"
|
2022-05-19 12:25:58 -04:00
|
|
|
#include "storage/helper.h"
|
2022-03-22 09:50:26 -04:00
|
|
|
|
|
|
|
/**********************************************************************************************************************************/
|
2023-01-02 15:24:51 +07:00
|
|
|
FN_EXTERN String *
|
2022-03-22 09:50:26 -04:00
|
|
|
repoPathIsValid(const String *path)
|
|
|
|
{
|
|
|
|
FUNCTION_LOG_BEGIN(logLevelDebug);
|
|
|
|
FUNCTION_LOG_PARAM(STRING, path);
|
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ASSERT(path != NULL);
|
|
|
|
|
|
|
|
String *result = NULL;
|
|
|
|
|
|
|
|
MEM_CONTEXT_TEMP_BEGIN()
|
|
|
|
{
|
|
|
|
// Make sure there are no occurrences of //
|
|
|
|
if (strstr(strZ(path), "//") != NULL)
|
|
|
|
THROW_FMT(ParamInvalidError, "path '%s' cannot contain //", strZ(path));
|
|
|
|
|
|
|
|
// Make sure the path does not end with a slash
|
|
|
|
if (strEndsWith(path, FSLASH_STR))
|
|
|
|
path = strPath(path);
|
|
|
|
|
|
|
|
// Validate absolute paths
|
|
|
|
if (strBeginsWith(path, FSLASH_STR))
|
|
|
|
{
|
2022-05-19 12:25:58 -04:00
|
|
|
// Get the repo path using repo storage in case it is remotely configured
|
|
|
|
const String *const repoPath = storagePathP(storageRepo(), NULL);
|
|
|
|
|
2022-05-13 09:41:53 -04:00
|
|
|
// If the path is exactly equal to the repo path then the relative path is empty
|
2022-05-19 12:25:58 -04:00
|
|
|
if (strEq(path, repoPath))
|
2022-03-22 09:50:26 -04:00
|
|
|
{
|
2022-05-13 09:41:53 -04:00
|
|
|
MEM_CONTEXT_PRIOR_BEGIN()
|
|
|
|
{
|
|
|
|
result = strNew();
|
|
|
|
}
|
|
|
|
MEM_CONTEXT_PRIOR_END();
|
2022-03-22 09:50:26 -04:00
|
|
|
}
|
2022-05-13 09:41:53 -04:00
|
|
|
// Else check that the file path begins with the repo path
|
|
|
|
else
|
2022-03-22 09:50:26 -04:00
|
|
|
{
|
2022-05-19 12:25:58 -04:00
|
|
|
if (!strEq(repoPath, FSLASH_STR) && !strBeginsWith(path, strNewFmt("%s/", strZ(repoPath))))
|
2022-05-13 09:41:53 -04:00
|
|
|
{
|
|
|
|
THROW_FMT(
|
|
|
|
ParamInvalidError, "absolute path '%s' is not in base path '%s'", strZ(path),
|
|
|
|
strZ(cfgOptionDisplay(cfgOptRepoPath)));
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_CONTEXT_PRIOR_BEGIN()
|
|
|
|
{
|
|
|
|
// Get the relative part of the path/file
|
2022-05-19 12:25:58 -04:00
|
|
|
result = strSub(path, strEq(repoPath, FSLASH_STR) ? 1 : strSize(repoPath) + 1);
|
2022-05-13 09:41:53 -04:00
|
|
|
}
|
|
|
|
MEM_CONTEXT_PRIOR_END();
|
2022-03-22 09:50:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MEM_CONTEXT_PRIOR_BEGIN()
|
|
|
|
{
|
|
|
|
result = strDup(path);
|
|
|
|
}
|
|
|
|
MEM_CONTEXT_PRIOR_END();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MEM_CONTEXT_TEMP_END();
|
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN(STRING, result);
|
|
|
|
}
|