agentfs-sdk 0.4.0-pre.2 → 0.4.0-pre.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/filesystem.js +16 -7
  2. package/package.json +1 -1
@@ -45,6 +45,7 @@ export class Filesystem {
45
45
  CREATE TABLE IF NOT EXISTS fs_inode (
46
46
  ino INTEGER PRIMARY KEY AUTOINCREMENT,
47
47
  mode INTEGER NOT NULL,
48
+ nlink INTEGER NOT NULL DEFAULT 0,
48
49
  uid INTEGER NOT NULL DEFAULT 0,
49
50
  gid INTEGER NOT NULL DEFAULT 0,
50
51
  size INTEGER NOT NULL DEFAULT 0,
@@ -111,8 +112,8 @@ export class Filesystem {
111
112
  if (!root) {
112
113
  const now = Math.floor(Date.now() / 1000);
113
114
  const insertStmt = this.db.prepare(`
114
- INSERT INTO fs_inode (ino, mode, uid, gid, size, atime, mtime, ctime)
115
- VALUES (?, ?, 0, 0, 0, ?, ?, ?)
115
+ INSERT INTO fs_inode (ino, mode, nlink, uid, gid, size, atime, mtime, ctime)
116
+ VALUES (?, ?, 1, 0, 0, 0, ?, ?, ?)
116
117
  `);
117
118
  await insertStmt.run(this.rootIno, DEFAULT_DIR_MODE, now, now, now);
118
119
  }
@@ -213,6 +214,9 @@ export class Filesystem {
213
214
  VALUES (?, ?, ?)
214
215
  `);
215
216
  await stmt.run(name, parentIno, ino);
217
+ // Increment link count
218
+ const updateStmt = this.db.prepare('UPDATE fs_inode SET nlink = nlink + 1 WHERE ino = ?');
219
+ await updateStmt.run(ino);
216
220
  }
217
221
  /**
218
222
  * Ensure parent directories exist
@@ -246,9 +250,9 @@ export class Filesystem {
246
250
  * Get link count for an inode
247
251
  */
248
252
  async getLinkCount(ino) {
249
- const stmt = this.db.prepare('SELECT COUNT(*) as count FROM fs_dentry WHERE ino = ?');
253
+ const stmt = this.db.prepare('SELECT nlink FROM fs_inode WHERE ino = ?');
250
254
  const result = await stmt.get(ino);
251
- return result.count;
255
+ return result?.nlink ?? 0;
252
256
  }
253
257
  async getInodeMode(ino) {
254
258
  const stmt = this.db.prepare('SELECT mode FROM fs_inode WHERE ino = ?');
@@ -376,6 +380,9 @@ export class Filesystem {
376
380
  WHERE parent_ino = ? AND name = ?
377
381
  `);
378
382
  await stmt.run(parent.parentIno, parent.name);
383
+ // Decrement link count
384
+ const decrementStmt = this.db.prepare('UPDATE fs_inode SET nlink = nlink - 1 WHERE ino = ?');
385
+ await decrementStmt.run(ino);
379
386
  // Check if this was the last link to the inode
380
387
  const linkCount = await this.getLinkCount(ino);
381
388
  if (linkCount === 0) {
@@ -394,7 +401,7 @@ export class Filesystem {
394
401
  async stat(path) {
395
402
  const { normalizedPath, ino } = await this.resolvePathOrThrow(path, 'stat');
396
403
  const stmt = this.db.prepare(`
397
- SELECT ino, mode, uid, gid, size, atime, mtime, ctime
404
+ SELECT ino, mode, nlink, uid, gid, size, atime, mtime, ctime
398
405
  FROM fs_inode
399
406
  WHERE ino = ?
400
407
  `);
@@ -407,11 +414,10 @@ export class Filesystem {
407
414
  message: 'no such file or directory',
408
415
  });
409
416
  }
410
- const nlink = await this.getLinkCount(ino);
411
417
  return {
412
418
  ino: row.ino,
413
419
  mode: row.mode,
414
- nlink: nlink,
420
+ nlink: row.nlink,
415
421
  uid: row.uid,
416
422
  gid: row.gid,
417
423
  size: row.size,
@@ -529,6 +535,9 @@ export class Filesystem {
529
535
  WHERE parent_ino = ? AND name = ?
530
536
  `);
531
537
  await stmt.run(parentIno, name);
538
+ // Decrement link count
539
+ const decrementStmt = this.db.prepare('UPDATE fs_inode SET nlink = nlink - 1 WHERE ino = ?');
540
+ await decrementStmt.run(ino);
532
541
  const linkCount = await this.getLinkCount(ino);
533
542
  if (linkCount === 0) {
534
543
  const deleteInodeStmt = this.db.prepare('DELETE FROM fs_inode WHERE ino = ?');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentfs-sdk",
3
- "version": "0.4.0-pre.2",
3
+ "version": "0.4.0-pre.3",
4
4
  "description": "AgentFS SDK",
5
5
  "main": "dist/index_node.js",
6
6
  "types": "dist/index_node.d.ts",