From b3ac80f3b05c25626df7588eee5aa61070e5384e Mon Sep 17 00:00:00 2001 From: Dwynr Date: Thu, 7 Nov 2024 18:57:55 +0100 Subject: [PATCH] fix: appy valid path checks to local tree aswell --- package-lock.json | 4 +- package.json | 2 +- src/lib/filesystems/local.ts | 49 ++++++++- src/lib/filesystems/remote.ts | 180 ++++++++++------------------------ 4 files changed, 101 insertions(+), 134 deletions(-) diff --git a/package-lock.json b/package-lock.json index c19f582..57cffd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@filen/sync", - "version": "0.1.74", + "version": "0.1.76", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@filen/sync", - "version": "0.1.74", + "version": "0.1.76", "license": "AGPLv3", "dependencies": { "@filen/sdk": "^0.1.175", diff --git a/package.json b/package.json index 66837f3..c792139 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@filen/sync", - "version": "0.1.75", + "version": "0.1.76", "description": "Filen Sync", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/lib/filesystems/local.ts b/src/lib/filesystems/local.ts index b8bad7f..89a7eb4 100644 --- a/src/lib/filesystems/local.ts +++ b/src/lib/filesystems/local.ts @@ -6,7 +6,10 @@ import { replacePathStartWithFromAndTo, pathIncludesDotFile, normalizeUTime, - isAbsolutePathIgnoredByDefault + isAbsolutePathIgnoredByDefault, + isPathOverMaxLength, + isNameOverMaxLength, + isValidPath } from "../../utils" import pathModule from "path" import process from "process" @@ -57,6 +60,9 @@ export type LocalTreeIgnoredReason = | "invalidType" | "duplicate" | "permissions" + | "pathLength" + | "invalidPath" + | "nameLength" export type LocalTreeIgnored = { localPath: string @@ -94,7 +100,6 @@ export class LocalFileSystem { public readonly itemsMutex = new Semaphore(1) public readonly mutex = new Semaphore(1) public readonly mkdirMutex = new Semaphore(1) - public readonly listSemaphore = new Semaphore(128) public readonly watcherMutex = new Semaphore(1) public watcherInstanceFallbackInterval: ReturnType | undefined = undefined public ignoredCache = new Map() @@ -115,9 +120,45 @@ export class LocalFileSystem { return this.ignoredCache.get(entry.path)! } - const entryPath = "/" + entry.path + const entryPath = entry.path.startsWith("/") ? entry.path : "/" + entry.path const absolutePath = pathModule.join(this.sync.syncPair.localPath, entry.path) + if (isPathOverMaxLength(absolutePath)) { + this.ignoredCache.set(entry.path, { + ignored: true, + reason: "pathLength" + }) + + return { + ignored: true, + reason: "pathLength" + } + } + + if (isNameOverMaxLength(entry.name)) { + this.ignoredCache.set(entry.path, { + ignored: true, + reason: "nameLength" + }) + + return { + ignored: true, + reason: "nameLength" + } + } + + if (!isValidPath(absolutePath)) { + this.ignoredCache.set(entry.path, { + ignored: true, + reason: "invalidPath" + }) + + return { + ignored: true, + reason: "invalidPath" + } + } + if (isRelativePathIgnoredByDefault(entryPath) || isAbsolutePathIgnoredByDefault(absolutePath)) { this.ignoredCache.set(entry.path, { ignored: true, @@ -215,7 +256,7 @@ export class LocalFileSystem { ignore: [".filen.trash.local/**/*", "$RECYCLE.BIN/**/*", "System Volume Information/**/*"], suppressErrors: false, stats: true, - unique: true, + unique: false, objectMode: true }) diff --git a/src/lib/filesystems/remote.ts b/src/lib/filesystems/remote.ts index 5bab59b..3fc126d 100644 --- a/src/lib/filesystems/remote.ts +++ b/src/lib/filesystems/remote.ts @@ -133,149 +133,75 @@ export class RemoteFileSystem { return this.ignoredCache.get(key)! } - if (type === "directory") { - if (isPathOverMaxLength(absolutePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "pathLength" - }) - - return { - ignored: true, - reason: "pathLength" - } - } - - if (isNameOverMaxLength(name)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "nameLength" - }) - - return { - ignored: true, - reason: "nameLength" - } - } - - if (!isValidPath(absolutePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "invalidPath" - }) - - return { - ignored: true, - reason: "invalidPath" - } - } - - if (isRelativePathIgnoredByDefault(relativePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "defaultIgnore" - }) - - return { - ignored: true, - reason: "defaultIgnore" - } - } - - if (this.sync.ignorer.ignores(relativePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "filenIgnore" - }) - - return { - ignored: true, - reason: "filenIgnore" - } - } - - if (this.sync.excludeDotFiles && pathIncludesDotFile(relativePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "dotFile" - }) - - return { - ignored: true, - reason: "dotFile" - } - } - } else { - if (isPathOverMaxLength(absolutePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "pathLength" - }) + if (isPathOverMaxLength(absolutePath)) { + this.ignoredCache.set(key, { + ignored: true, + reason: "pathLength" + }) - return { - ignored: true, - reason: "pathLength" - } + return { + ignored: true, + reason: "pathLength" } + } - if (isNameOverMaxLength(name)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "nameLength" - }) + if (isNameOverMaxLength(name)) { + this.ignoredCache.set(key, { + ignored: true, + reason: "nameLength" + }) - return { - ignored: true, - reason: "nameLength" - } + return { + ignored: true, + reason: "nameLength" } + } - if (!isValidPath(absolutePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "invalidPath" - }) + if (!isValidPath(absolutePath)) { + this.ignoredCache.set(key, { + ignored: true, + reason: "invalidPath" + }) - return { - ignored: true, - reason: "invalidPath" - } + return { + ignored: true, + reason: "invalidPath" } + } - if (isRelativePathIgnoredByDefault(relativePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "defaultIgnore" - }) + if (isRelativePathIgnoredByDefault(relativePath)) { + this.ignoredCache.set(key, { + ignored: true, + reason: "defaultIgnore" + }) - return { - ignored: true, - reason: "defaultIgnore" - } + return { + ignored: true, + reason: "defaultIgnore" } + } - if (this.sync.ignorer.ignores(relativePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "filenIgnore" - }) + if (this.sync.ignorer.ignores(relativePath)) { + this.ignoredCache.set(key, { + ignored: true, + reason: "filenIgnore" + }) - return { - ignored: true, - reason: "filenIgnore" - } + return { + ignored: true, + reason: "filenIgnore" } + } - if (this.sync.excludeDotFiles && pathIncludesDotFile(relativePath)) { - this.ignoredCache.set(key, { - ignored: true, - reason: "dotFile" - }) + if (this.sync.excludeDotFiles && pathIncludesDotFile(relativePath)) { + this.ignoredCache.set(key, { + ignored: true, + reason: "dotFile" + }) - return { - ignored: true, - reason: "dotFile" - } + return { + ignored: true, + reason: "dotFile" } }