diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0049a514..9cd809f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,32 +7,26 @@ on: branches: ["main"] permissions: - contents: read + contents: read jobs: - test: - runs-on: ubuntu-latest + test: + runs-on: ubuntu-latest - steps: - - name: Setup repo - uses: actions/checkout@v3 - with: - fetch-depth: 0 - fetch-tags: true + steps: + - name: Setup repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true - - name: Setup Deno - uses: denoland/setup-deno@v2 - with: - deno-version: v2.5.0 + - name: Setup Deno + uses: denoland/setup-deno@v2 + with: + deno-version: v2.5.0 - - name: Run build - run: deno task build + - name: Run build + run: deno task build - - name: Run type check - run: deno task check - - - name: Run lint - run: deno task lint - - - name: Run tests - run: deno task test + - name: Run checks + run: deno task checks diff --git a/lib/spaces/disk_space_primitives.ts b/lib/spaces/disk_space_primitives.ts index 6c9b6a25..ed31b0a4 100644 --- a/lib/spaces/disk_space_primitives.ts +++ b/lib/spaces/disk_space_primitives.ts @@ -103,15 +103,7 @@ export class DiskSpacePrimitives implements SpacePrimitives { async getFileMeta(path: string, _observing?: boolean): Promise { const localPath = this.filenameToPath(path); try { - const s = await Deno.stat(localPath); - return { - name: path, - size: s.size, - contentType: lookupContentType(path), - created: s.birthtime?.getTime() || s.mtime?.getTime() || 0, - lastModified: s.mtime?.getTime() || 0, - perm: "rw", - }; + return this.fileInfoToFileMeta(path, await Deno.stat(localPath)); } catch (e: any) { if (e instanceof Deno.errors.NotFound) { throw notFoundError; @@ -121,6 +113,17 @@ export class DiskSpacePrimitives implements SpacePrimitives { } } + private fileInfoToFileMeta(path: string, s: Deno.FileInfo): FileMeta { + return { + name: path, + size: s.size, + contentType: lookupContentType(path), + created: s.birthtime?.getTime() || s.mtime?.getTime() || 0, + lastModified: s.mtime?.getTime() || 0, + perm: "rw", + }; + } + async deleteFile(path: string): Promise { const localPath = this.filenameToPath(path); try { @@ -176,14 +179,9 @@ export class DiskSpacePrimitives implements SpacePrimitives { try { const s = await Deno.stat(fullPath); const name = fullPath.substring(this.rootPath.length + 1); - allFiles.push({ - name: normalizeForwardSlashPath(name), - created: s.birthtime?.getTime() || s.mtime?.getTime() || 0, - lastModified: s.mtime?.getTime() || 0, - contentType: mime.getType(fullPath) || "application/octet-stream", - size: s.size, - perm: "rw", - }); + allFiles.push( + this.fileInfoToFileMeta(normalizeForwardSlashPath(name), s), + ); } catch (e: any) { if (e instanceof Deno.errors.NotFound) { // Ignore, temporariy file already deleted by the time we got here diff --git a/lib/spaces/sync.ts b/lib/spaces/sync.ts index fbdb83f1..49d3a048 100644 --- a/lib/spaces/sync.ts +++ b/lib/spaces/sync.ts @@ -71,7 +71,6 @@ export class SpaceSync extends EventEmitter { constructor( private primary: SpacePrimitives, private secondary: SpacePrimitives, - // public snapshot: SyncSnapshot, readonly options: SyncOptions, ) { super(); @@ -409,8 +408,8 @@ export class SpaceSync extends EventEmitter { } else if ( primaryMeta !== undefined && secondaryMeta !== undefined && snapshot.files.get(path) && - secondaryMeta.lastModified !== snapshot.files.get(path)![1] && - primaryMeta.lastModified === snapshot.files.get(path)![0] + primaryMeta.lastModified === snapshot.files.get(path)![0] && + secondaryMeta.lastModified !== snapshot.files.get(path)![1] ) { // File has changed on secondary, but not primary if (syncBack) {