Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mtime dates #101

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/classes/PermanentFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@permanentorg/sdk';
import {
deduplicateFileEntries,
generateAttributesForArchive,
generateAttributesForFile,
generateAttributesForFolder,
generateDefaultAttributes,
Expand Down Expand Up @@ -110,10 +111,15 @@ export class PermanentFileSystem {

public async getItemAttributes(itemPath: string): Promise<Attributes> {
if (isRootPath(itemPath)
|| isArchiveCataloguePath(itemPath)
|| isArchivePath(itemPath)) {
|| isArchiveCataloguePath(itemPath)) {
return generateDefaultAttributes(fs.constants.S_IFDIR);
}

if (isArchivePath(itemPath)) {
const archive = await this.loadArchive(itemPath);
return generateAttributesForArchive(archive);
}

const fileType = await this.getItemType(itemPath);
switch (fileType) {
case fs.constants.S_IFREG: {
Expand Down Expand Up @@ -302,6 +308,14 @@ export class PermanentFileSystem {
return archiveFolders;
}

private async loadArchive(requestedPath: string): Promise<Archive> {
if (!isArchivePath(requestedPath)) {
throw new Error('The requested path is not an archive');
}
const archiveSlug = getArchiveSlugFromPath(requestedPath);
return this.loadArchiveByArchiveSlug(archiveSlug);
}

private async loadFolder(requestedPath: string, overrideCache = false): Promise<Folder> {
const cachedFolder = this.folderCache.get(requestedPath);
if (cachedFolder && !overrideCache) {
Expand Down Expand Up @@ -337,7 +351,7 @@ export class PermanentFileSystem {
const archives = await this.loadArchives();
return archives.map((archive: Archive) => generateFileEntry(
`${archive.name} (${archive.slug})`,
generateDefaultAttributes(fs.constants.S_IFDIR),
generateAttributesForArchive(archive),
));
}

Expand All @@ -346,7 +360,7 @@ export class PermanentFileSystem {
const folders = await this.loadArchiveFolders(archiveId);
return folders.map((archiveFolder) => generateFileEntry(
`${archiveFolder.fileSystemCompatibleName}`,
generateDefaultAttributes(fs.constants.S_IFDIR),
generateAttributesForFolder(archiveFolder),
));
}

Expand Down
13 changes: 13 additions & 0 deletions src/utils/generateAttributesForArchive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'fs';
import { generateDefaultMode } from './generateDefaultMode';
import type { Attributes } from 'ssh2';
import type { Archive } from '@permanentorg/sdk';

export const generateAttributesForArchive = (archive: Archive): Attributes => ({
mode: generateDefaultMode(fs.constants.S_IFDIR),
uid: 0,
gid: 0,
size: 0,
atime: 0,
mtime: archive.updatedAt.getTime() / 1000,
});
2 changes: 1 addition & 1 deletion src/utils/generateAttributesForFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const generateAttributesForFile = (file?: File): Attributes => (
gid: 0,
size: file.size,
atime: 0,
mtime: file.updatedAt.getTime(),
mtime: file.updatedAt.getTime() / 1000,
}
: generateDefaultAttributes(fs.constants.S_IFREG)
);
2 changes: 1 addition & 1 deletion src/utils/generateAttributesForFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const generateAttributesForFolder = (folder: Folder): Attributes => ({
gid: 0,
size: folder.size,
atime: 0,
mtime: folder.updatedAt.getTime(),
mtime: folder.updatedAt.getTime() / 1000,
});
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './deduplicateFileEntries';
export * from './generateAttributesForArchive';
export * from './generateAttributesForFile';
export * from './generateAttributesForFolder';
export * from './generateDefaultAttributes';
Expand Down