/// import fs from "fs-extra"; import type Sync from "../sync"; import { type CloudItem } from "@filen/sdk"; import { Semaphore } from "../../semaphore"; export type LocalItem = { lastModified: number; type: "file" | "directory"; path: string; size: number; creation: number; inode: number; }; export type LocalDirectoryTree = Record; export type LocalDirectoryINodes = Record; export type LocalTree = { tree: LocalDirectoryTree; inodes: LocalDirectoryINodes; size: number; }; export type LocalTreeError = { localPath: string; relativePath: string; error: Error; uuid: string; }; export type LocalTreeIgnoredReason = "dotFile" | "filenIgnore" | "defaultIgnore" | "empty" | "symlink" | "invalidType" | "duplicate" | "permissions" | "pathLength" | "invalidPath" | "nameLength"; export type LocalTreeIgnored = { localPath: string; relativePath: string; reason: LocalTreeIgnoredReason; }; /** * LocalFileSystem * @date 3/2/2024 - 12:38:22 PM * * @export * @class LocalFileSystem * @typedef {LocalFileSystem} */ export declare class LocalFileSystem { private readonly sync; lastDirectoryChangeTimestamp: number; getDirectoryTreeCache: { timestamp: number; tree: LocalDirectoryTree; inodes: LocalDirectoryINodes; ignored: LocalTreeIgnored[]; errors: LocalTreeError[]; size: number; }; watcherRunning: boolean; private watcherInstanceParcel; private watcherInstanceNode; readonly itemsMutex: Semaphore; readonly mutex: Semaphore; readonly mkdirMutex: Semaphore; readonly watcherMutex: Semaphore; watcherInstanceFallbackInterval: ReturnType | undefined; ignoredCache: Map; /** * Creates an instance of LocalFileSystem. * * @constructor * @public * @param {Sync} sync */ constructor(sync: Sync); isPathIgnored(relativePath: string, absolutePath: string, type: "file" | "directory"): { ignored: true; reason: LocalTreeIgnoredReason; } | { ignored: false; }; getDirectoryTree(): Promise<{ result: LocalTree; errors: LocalTreeError[]; ignored: LocalTreeIgnored[]; changed: boolean; }>; /** * Start the local sync directory watcher. * @date 3/2/2024 - 12:38:00 PM * * @public * @async * @returns {Promise} */ startDirectoryWatcher(): Promise; /** * Stop the local sync directory watcher. * @date 3/2/2024 - 12:37:48 PM * * @public * @async * @returns {Promise} */ stopDirectoryWatcher(): Promise; /** * Wait for local directory updates to be done. * Sometimes the user might copy a lot of new files, folders etc. * We want to wait (or at least try) until all local operations are done until we start syncing. * This can save a lot of sync cycles. * @date 3/1/2024 - 10:40:14 PM * * @public * @async * @returns {Promise} */ waitForLocalDirectoryChanges(): Promise; /** * Creates a hash of a file using streams. * * @public * @async * @param {{ * relativePath: string * algorithm: "sha512" | "md5" | "sha256" * }} param0 * @param {string} param0.relativePath * @param {("sha512" | "md5" | "sha256")} param0.algorithm * @returns {Promise} */ createFileHash({ relativePath, algorithm }: { relativePath: string; algorithm: "sha512" | "md5" | "sha256"; }): Promise; /** * Create a directory inside the local sync path. Recursively creates intermediate directories if needed. * @date 3/2/2024 - 12:36:23 PM * * @public * @async * @param {{ relativePath: string }} param0 * @param {string} param0.relativePath * @returns {Promise} */ mkdir({ relativePath }: { relativePath: string; }): Promise; unlink({ relativePath, permanent }: { relativePath: string; permanent?: boolean; }): Promise; rename({ fromRelativePath, toRelativePath }: { fromRelativePath: string; toRelativePath: string; }): Promise; /** * Upload a local file. * * @public * @async * @param {{ relativePath: string, passedMD5Hash?: string }} param0 * @param {string} param0.relativePath * @param {string} param0.passedMD5Hash * @returns {Promise} */ upload({ relativePath, passedMD5Hash }: { relativePath: string; passedMD5Hash?: string; }): Promise; isPathWritable(path: string): Promise; isPathReadable(path: string): Promise; pathExists(path: string): Promise; } export default LocalFileSystem;