Skip to content

Commit

Permalink
fix: appy valid path checks to local tree aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Nov 7, 2024
1 parent 2526b63 commit b3ac80f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 134 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
49 changes: 45 additions & 4 deletions src/lib/filesystems/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
replacePathStartWithFromAndTo,
pathIncludesDotFile,
normalizeUTime,
isAbsolutePathIgnoredByDefault
isAbsolutePathIgnoredByDefault,
isPathOverMaxLength,
isNameOverMaxLength,
isValidPath
} from "../../utils"
import pathModule from "path"
import process from "process"
Expand Down Expand Up @@ -57,6 +60,9 @@ export type LocalTreeIgnoredReason =
| "invalidType"
| "duplicate"
| "permissions"
| "pathLength"
| "invalidPath"
| "nameLength"

export type LocalTreeIgnored = {
localPath: string
Expand Down Expand Up @@ -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<typeof setInterval> | undefined = undefined
public ignoredCache = new Map<string, { ignored: true; reason: LocalTreeIgnoredReason } | { ignored: false }>()
Expand All @@ -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,
Expand Down Expand Up @@ -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
})

Expand Down
180 changes: 53 additions & 127 deletions src/lib/filesystems/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down

0 comments on commit b3ac80f

Please sign in to comment.