Skip to content

Commit

Permalink
feat: improve default ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Sep 21, 2024
1 parent 2704841 commit 2820c97
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
23 changes: 21 additions & 2 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@filen/sync",
"version": "0.1.68",
"version": "0.1.69",
"description": "Filen Sync",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -37,6 +37,7 @@
"@jest/globals": "^29.7.0",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.12",
"@types/micromatch": "^4.0.9",
"@types/mime-types": "^2.1.4",
"@types/uuid": "^9.0.8",
"@types/write-file-atomic": "^4.0.3",
Expand All @@ -58,6 +59,7 @@
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"ignore": "^5.3.1",
"micromatch": "^4.0.8",
"node-watch": "^0.7.4",
"pino": "^9.3.2",
"rotating-file-stream": "^3.2.3",
Expand Down
40 changes: 38 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,43 @@ export const DEFAULT_IGNORED = {
"thumbs.db",
"ntuser.dat",
".trash",
".filen.trash.local"
".filen.trash.local",
"AUX",
"PRN",
"NUL",
"CON",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
"COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9"
],
extensions: [".tmp", ".temp", ".ffs_tmp", ".temporary", ".crdownload", ".~cr", ".thumbdata"]
extensions: [".tmp", ".temp", ".ffs_tmp", ".temporary", ".crdownload", ".~cr", ".thumbdata"],
absoluteGlobs: [
"C:/$WINDOWS.~BT/**/*",
"C:/$Windows.~WS/**/*",
"C:/$WinREAgent/**/*",
"C:/Windows/**/*",
"C:/OneDriveTemp/**/*",
"C:/PerfLogs/**/*",
"C:/ProgramData/**/*",
"C:/Program Files/**/*",
"C:/Program Files (x86)/**/*",
"/share/Trash/**/*",
"C:/Users/*/AppData/**/*"
],
relativeGlobs: [".filen.trash.local/**/*", "$RECYCLE.BIN/**/*", ".Trash/**/*", ".local/share/Trash/**/*", "local/share/Trash/**/*"]
}
5 changes: 3 additions & 2 deletions src/lib/filesystems/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
serializeError,
replacePathStartWithFromAndTo,
pathIncludesDotFile,
normalizeUTime
normalizeUTime,
isAbsolutePathIgnoredByDefault
} from "../../utils"
import pathModule from "path"
import process from "process"
Expand Down Expand Up @@ -197,7 +198,7 @@ export class LocalFileSystem {

const itemPath = pathModule.join(this.sync.syncPair.localPath, entryItem.path)

if (isRelativePathIgnoredByDefault(entryPath)) {
if (isRelativePathIgnoredByDefault(entryPath) || isAbsolutePathIgnoredByDefault(itemPath)) {
this.getDirectoryTreeCache.ignored.push({
localPath: itemPath,
relativePath: entryItem.path,
Expand Down
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DEFAULT_IGNORED } from "./constants"
import pathModule from "path"
import crypto from "crypto"
import { exec } from "child_process"
import micromatch from "micromatch"

/**
* Chunk large Promise.all executions.
Expand Down Expand Up @@ -201,7 +202,14 @@ export function isNameIgnoredByDefault(name: string): boolean {
}

export function isRelativePathIgnoredByDefault(path: string): boolean {
return path.split("/").some(part => part.length > 0 && isNameIgnoredByDefault(part))
return (
path.split("/").some(part => part.length > 0 && isNameIgnoredByDefault(part)) ||
micromatch.isMatch(path, DEFAULT_IGNORED.relativeGlobs)
)
}

export function isAbsolutePathIgnoredByDefault(path: string): boolean {
return micromatch.isMatch(path, DEFAULT_IGNORED.absoluteGlobs)
}

export type SerializedError = {
Expand Down

0 comments on commit 2820c97

Please sign in to comment.