From 2820c9745cd12bd6bd20ae1e8ae37bafffd3c4c1 Mon Sep 17 00:00:00 2001 From: Dwynr Date: Sat, 21 Sep 2024 03:40:11 +0200 Subject: [PATCH] feat: improve default ignored --- package-lock.json | 23 +++++++++++++++++++-- package.json | 4 +++- src/constants.ts | 40 ++++++++++++++++++++++++++++++++++-- src/lib/filesystems/local.ts | 5 +++-- src/utils.ts | 10 ++++++++- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5252425..e79247c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@filen/sync", - "version": "0.1.66", + "version": "0.1.68", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@filen/sync", - "version": "0.1.66", + "version": "0.1.68", "license": "AGPLv3", "dependencies": { "@filen/sdk": "^0.1.167", @@ -14,6 +14,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", @@ -24,6 +25,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", @@ -2458,6 +2460,13 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/braces": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/braces/-/braces-3.0.4.tgz", + "integrity": "sha512-0WR3b8eaISjEW7RpZnclONaLFDf7buaowRHdqLp4vLj54AsSAYWfh3DRbfiYJY9XDxMgx1B4sE1Afw2PGpuHOA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/fs-extra": { "version": "11.0.4", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.4.tgz", @@ -2526,6 +2535,16 @@ "@types/node": "*" } }, + "node_modules/@types/micromatch": { + "version": "4.0.9", + "resolved": "https://registry.npmjs.org/@types/micromatch/-/micromatch-4.0.9.tgz", + "integrity": "sha512-7V+8ncr22h4UoYRLnLXSpTxjQrNUXtWHGeMPRJt1nULXI57G9bIcpyrHlmrQ7QK24EyyuXvYcSSWAM8GA9nqCg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/braces": "*" + } + }, "node_modules/@types/mime-types": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", diff --git a/package.json b/package.json index 786f888..764e4d6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/src/constants.ts b/src/constants.ts index 1afadb5..c9d7ed2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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/**/*"] } diff --git a/src/lib/filesystems/local.ts b/src/lib/filesystems/local.ts index ea7730d..88c2404 100644 --- a/src/lib/filesystems/local.ts +++ b/src/lib/filesystems/local.ts @@ -5,7 +5,8 @@ import { serializeError, replacePathStartWithFromAndTo, pathIncludesDotFile, - normalizeUTime + normalizeUTime, + isAbsolutePathIgnoredByDefault } from "../../utils" import pathModule from "path" import process from "process" @@ -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, diff --git a/src/utils.ts b/src/utils.ts index a09f8cd..0231f0c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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. @@ -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 = {