From ccd667be067a5148545d7ccc958e29e65a2ac458 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 29 Jun 2022 20:12:20 +0200 Subject: validate revisions, set threads to 4, do not allow concurent updates --- src/fs.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'src/fs.c') diff --git a/src/fs.c b/src/fs.c index ee7a39d..ee11a1b 100644 --- a/src/fs.c +++ b/src/fs.c @@ -7,6 +7,11 @@ #include #include +#ifdef _WIN32 +#include +#include +#endif + #include "fs.h" #ifdef _WIN32 @@ -57,6 +62,66 @@ int isDir(const char* path) return S_ISDIR(sb.st_mode); } +int isRelativePath(const char* path) +{ + if (!path) + return 0; + else if (*path == *OS_PATH_SEP) + return 0; +#ifdef _WIN32 + else if (!PathIsRelativeA(path)) + return 0; +#endif + return 1; +} + +int leavesRelativePath(const char* path) +{ + if (!path || !isRelativePath(path)) + return 0; + + int depth = 0; + const char* head = path; + const char* tail = head; + + while (*tail) + { + ++tail; + if (*tail == *OS_PATH_SEP || *tail == '\0') + { + size_t size = (size_t)(tail-head); + if (!size) + continue; + else if (!strncmp(head, "..", size)) + depth -= 1; + else if (strncmp(head, ".", size)) + depth += 1; + + if (depth < 0) + return 1; + + head = tail + 1; + } + } + return 0; +} + +char* normalizeUnixPath(char* path) +{ + char* head = path; + if (head) + { + while (*head) + { + if (*head == '/') + *head = *OS_PATH_SEP; + + ++head; + } + } + + return path; +} int makeDir(const char* path) { char pathcpy[PATH_MAX]; -- cgit v1.2.3