Skip to content

Commit

Permalink
fix: virtual file, write, unlink, chmod, rename, truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
divyenduz committed Nov 10, 2023
1 parent 3616a9b commit 7f9a334
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/fuse-client/syscalls/chmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const chmod: (backend: SQLiteBackend) => MountOptions["chmod"] = (
) => {
return async (path, mode, cb) => {
console.info("chmod(%s, %d)", path, mode);

if (backend.isVirtualFile(path)) {
cb(0);
return;
}

const r = await backend.updateMode(path, mode);
match(r)
.with({ status: "ok" }, () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/fuse-client/syscalls/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export const rename: (backend: SQLiteBackend) => MountOptions["rename"] = (
) => {
return async (srcPath, destPath, cb) => {
console.info("rename(%s, %s)", srcPath, destPath);

if (backend.isVirtualFile(srcPath)) {
await backend.createFile(destPath, "file", 33188, 0, 0);
cb(0);
return;
}

const r = await backend.renameFile(srcPath, destPath);
if (r.status === "ok") {
cb(0);
Expand Down
6 changes: 6 additions & 0 deletions packages/fuse-client/syscalls/truncate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export const truncate: (backend: SQLiteBackend) => MountOptions["truncate"] = (
) => {
return async (path, size, cb) => {
console.info("truncate(%s, %d)", path, size);

if (backend.isVirtualFile(path)) {
cb(0);
return;
}

const r = await backend.truncateFile(path, size);
await match(r)
.with({ status: "ok" }, async (r) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/fuse-client/syscalls/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export const unlink: (backend: SQLiteBackend) => MountOptions["unlink"] = (
) => {
return async (path, cb) => {
console.info("unlink(%s)", path);

if (backend.isVirtualFile(path)) {
cb(0);
return;
}

const r = await backend.deleteFile(path);
if (r.status === "ok") {
cb(0);
Expand Down
7 changes: 7 additions & 0 deletions packages/fuse-client/syscalls/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export const write: (backend: SQLiteBackend) => MountOptions["write"] = (
) => {
return async (path, fd, buf, len, pos, cb) => {
console.info("write(%s, %d, %d, %d)", path, fd, len, pos);

if (backend.isVirtualFile(path)) {
const chunk = Buffer.from(buf, pos, len);
cb(chunk.length);
return;
}

const chunk = Buffer.from(buf, pos, len);
// TODO: This may throw (because of flush!, what should happen then?)
await backend.write(path, { content: chunk, offset: pos, size: len });
Expand Down
1 change: 1 addition & 0 deletions packages/sqlite-backend/SQLiteBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ export class SQLiteBackend implements Backend {
}

async deleteFile(filepath: string) {
const links = await this.prisma.link.findMany();
try {
const { link } = await this.prisma.$transaction(async (tx) => {
const link = await this.prisma.link.findFirstOrThrow({
Expand Down

0 comments on commit 7f9a334

Please sign in to comment.