@zenfs/core 0.0.7 → 0.0.8

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.
package/dist/FileIndex.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Stats, FileType } from './stats.js';
2
- import * as path from 'path';
2
+ import * as path from './emulation/path.js';
3
3
  /**
4
4
  * A simple class for storing a filesystem index. Assumes that all paths passed
5
5
  * to it are *absolute* paths.
@@ -219,7 +219,7 @@ export class FileIndex {
219
219
  */
220
220
  _split_path(p) {
221
221
  const dirpath = path.dirname(p);
222
- const itemname = p.substr(dirpath.length + (dirpath === '/' ? 0 : 1));
222
+ const itemname = p.slice(dirpath.length + (dirpath === '/' ? 0 : 1));
223
223
  return [dirpath, itemname];
224
224
  }
225
225
  }
@@ -11,7 +11,7 @@ var _a;
11
11
  import { SynchronousFileSystem } from '../filesystem.js';
12
12
  import { ApiError, ErrorCode } from '../ApiError.js';
13
13
  import { FileFlag, PreloadFile } from '../file.js';
14
- import * as path from 'path';
14
+ import { join } from '../emulation/path.js';
15
15
  import { Cred } from '../cred.js';
16
16
  import { CreateBackend } from './backend.js';
17
17
  /**
@@ -185,7 +185,7 @@ export class AsyncMirror extends SynchronousFileSystem {
185
185
  }
186
186
  const files = yield this._async.readdir(p, Cred.Root);
187
187
  for (const file of files) {
188
- yield copyItem(path.join(p, file));
188
+ yield copyItem(join(p, file));
189
189
  }
190
190
  }), copyFile = (p, mode) => __awaiter(this, void 0, void 0, function* () {
191
191
  const data = yield this._async.readFile(p, null, FileFlag.getFileFlag('r'), Cred.Root);
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import * as path from 'path';
10
+ import { dirname, basename, join, resolve } from '../emulation/path.js';
11
11
  import { ApiError, ErrorCode } from '../ApiError.js';
12
12
  import { W_OK, R_OK } from '../emulation/constants.js';
13
13
  import { PreloadFile, FileFlag } from '../file.js';
@@ -204,7 +204,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
204
204
  c.removeAll();
205
205
  }
206
206
  try {
207
- const tx = this.store.beginTransaction('readwrite'), oldParent = path.dirname(oldPath), oldName = path.basename(oldPath), newParent = path.dirname(newPath), newName = path.basename(newPath),
207
+ const tx = this.store.beginTransaction('readwrite'), oldParent = dirname(oldPath), oldName = basename(oldPath), newParent = dirname(newPath), newName = basename(newPath),
208
208
  // Remove oldPath from parent's directory listing.
209
209
  oldDirNode = yield this.findINode(tx, oldParent), oldDirList = yield this.getDirListing(tx, oldParent, oldDirNode);
210
210
  if (!oldDirNode.toStats().hasAccess(W_OK, cred)) {
@@ -350,7 +350,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
350
350
  // update is required.
351
351
  const tx = this.store.beginTransaction('readwrite'),
352
352
  // We use the _findInode helper because we actually need the INode id.
353
- fileInodeId = yield this._findINode(tx, path.dirname(p), path.basename(p)), fileInode = yield this.getINode(tx, p, fileInodeId), inodeChanged = fileInode.update(stats);
353
+ fileInodeId = yield this._findINode(tx, dirname(p), basename(p)), fileInode = yield this.getINode(tx, p, fileInodeId), inodeChanged = fileInode.update(stats);
354
354
  try {
355
355
  // Sync data.
356
356
  yield tx.put(fileInode.id, data, true);
@@ -393,7 +393,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
393
393
  */
394
394
  _findINode(tx, parent, filename, visited = new Set()) {
395
395
  return __awaiter(this, void 0, void 0, function* () {
396
- const currentPath = path.posix.join(parent, filename);
396
+ const currentPath = join(parent, filename);
397
397
  if (visited.has(currentPath)) {
398
398
  throw new ApiError(ErrorCode.EIO, 'Infinite loop detected while finding inode', currentPath);
399
399
  }
@@ -424,7 +424,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
424
424
  return id;
425
425
  }
426
426
  else {
427
- throw ApiError.ENOENT(path.resolve(parent, filename));
427
+ throw ApiError.ENOENT(resolve(parent, filename));
428
428
  }
429
429
  }
430
430
  }
@@ -441,7 +441,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
441
441
  return id;
442
442
  }
443
443
  else {
444
- throw ApiError.ENOENT(path.resolve(parent, filename));
444
+ throw ApiError.ENOENT(resolve(parent, filename));
445
445
  }
446
446
  }
447
447
  });
@@ -453,7 +453,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
453
453
  */
454
454
  findINode(tx, p, visited = new Set()) {
455
455
  return __awaiter(this, void 0, void 0, function* () {
456
- const id = yield this._findINode(tx, path.dirname(p), path.basename(p), visited);
456
+ const id = yield this._findINode(tx, dirname(p), basename(p), visited);
457
457
  return this.getINode(tx, p, id);
458
458
  });
459
459
  }
@@ -532,7 +532,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
532
532
  */
533
533
  commitNewFile(tx, p, type, mode, cred, data) {
534
534
  return __awaiter(this, void 0, void 0, function* () {
535
- const parentDir = path.dirname(p), fname = path.basename(p), parentNode = yield this.findINode(tx, parentDir), dirListing = yield this.getDirListing(tx, parentDir, parentNode), currTime = new Date().getTime();
535
+ const parentDir = dirname(p), fname = basename(p), parentNode = yield this.findINode(tx, parentDir), dirListing = yield this.getDirListing(tx, parentDir, parentNode), currTime = new Date().getTime();
536
536
  //Check that the creater has correct access
537
537
  if (!parentNode.toStats().hasAccess(W_OK, cred)) {
538
538
  throw ApiError.EACCES(p);
@@ -583,7 +583,7 @@ export class AsyncKeyValueFileSystem extends BaseFileSystem {
583
583
  if (this._cache) {
584
584
  this._cache.remove(p);
585
585
  }
586
- const tx = this.store.beginTransaction('readwrite'), parent = path.dirname(p), parentNode = yield this.findINode(tx, parent), parentListing = yield this.getDirListing(tx, parent, parentNode), fileName = path.basename(p);
586
+ const tx = this.store.beginTransaction('readwrite'), parent = dirname(p), parentNode = yield this.findINode(tx, parent), parentListing = yield this.getDirListing(tx, parent, parentNode), fileName = basename(p);
587
587
  if (!parentListing[fileName]) {
588
588
  throw ApiError.ENOENT(p);
589
589
  }
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  var _a;
11
11
  import { BaseFileSystem } from '../filesystem.js';
12
- import * as path from 'path';
12
+ import { relative, join } from '../emulation/path.js';
13
13
  import { ApiError } from '../ApiError.js';
14
14
  import { Cred } from '../cred.js';
15
15
  import { CreateBackend } from './backend.js';
@@ -80,7 +80,7 @@ function translateError(folder, e) {
80
80
  const err = e;
81
81
  let p = err.path;
82
82
  if (p) {
83
- p = '/' + path.relative(folder, p);
83
+ p = '/' + relative(folder, p);
84
84
  err.message = err.message.replace(err.path, p);
85
85
  err.path = p;
86
86
  }
@@ -112,10 +112,10 @@ function wrapFunction(name, wrapFirst, wrapSecond) {
112
112
  return function () {
113
113
  if (arguments.length > 0) {
114
114
  if (wrapFirst) {
115
- arguments[0] = path.join(this._folder, arguments[0]);
115
+ arguments[0] = join(this._folder, arguments[0]);
116
116
  }
117
117
  if (wrapSecond) {
118
- arguments[1] = path.join(this._folder, arguments[1]);
118
+ arguments[1] = join(this._folder, arguments[1]);
119
119
  }
120
120
  arguments[arguments.length - 1] = wrapCallback(this._folder, arguments[arguments.length - 1]);
121
121
  }
@@ -127,10 +127,10 @@ function wrapFunction(name, wrapFirst, wrapSecond) {
127
127
  return function () {
128
128
  try {
129
129
  if (wrapFirst) {
130
- arguments[0] = path.join(this._folder, arguments[0]);
130
+ arguments[0] = join(this._folder, arguments[0]);
131
131
  }
132
132
  if (wrapSecond) {
133
- arguments[1] = path.join(this._folder, arguments[1]);
133
+ arguments[1] = join(this._folder, arguments[1]);
134
134
  }
135
135
  return this._wrapped[name].apply(this._wrapped, arguments);
136
136
  }
@@ -13,7 +13,7 @@ import { ApiError, ErrorCode } from '../ApiError.js';
13
13
  import { FileFlag, ActionType, PreloadFile } from '../file.js';
14
14
  import { Stats } from '../stats.js';
15
15
  import LockedFS from './Locked.js';
16
- import * as path from 'path';
16
+ import { resolve, dirname } from '../emulation/path.js';
17
17
  import { Cred } from '../cred.js';
18
18
  import { CreateBackend } from './backend.js';
19
19
  /**
@@ -187,7 +187,7 @@ export class UnlockedOverlayFS extends BaseFileSystem {
187
187
  if (yield this._readable.exists(oldPath, cred)) {
188
188
  for (const name of yield this._readable.readdir(oldPath, cred)) {
189
189
  // Recursion! Should work for any nested files / folders.
190
- yield this.rename(path.resolve(oldPath, name), path.resolve(newPath, name), cred);
190
+ yield this.rename(resolve(oldPath, name), resolve(newPath, name), cred);
191
191
  }
192
192
  }
193
193
  }
@@ -242,7 +242,7 @@ export class UnlockedOverlayFS extends BaseFileSystem {
242
242
  if (this._readable.existsSync(oldPath, cred)) {
243
243
  this._readable.readdirSync(oldPath, cred).forEach(name => {
244
244
  // Recursion! Should work for any nested files / folders.
245
- this.renameSync(path.resolve(oldPath, name), path.resolve(newPath, name), cred);
245
+ this.renameSync(resolve(oldPath, name), resolve(newPath, name), cred);
246
246
  });
247
247
  }
248
248
  }
@@ -622,10 +622,10 @@ export class UnlockedOverlayFS extends BaseFileSystem {
622
622
  * should they not exist. Use modes from the read-only storage.
623
623
  */
624
624
  createParentDirectories(p, cred) {
625
- let parent = path.dirname(p), toCreate = [];
625
+ let parent = dirname(p), toCreate = [];
626
626
  while (!this._writable.existsSync(parent, cred)) {
627
627
  toCreate.push(parent);
628
- parent = path.dirname(parent);
628
+ parent = dirname(parent);
629
629
  }
630
630
  toCreate = toCreate.reverse();
631
631
  for (const p of toCreate) {
@@ -634,10 +634,10 @@ export class UnlockedOverlayFS extends BaseFileSystem {
634
634
  }
635
635
  createParentDirectoriesAsync(p, cred) {
636
636
  return __awaiter(this, void 0, void 0, function* () {
637
- let parent = path.dirname(p), toCreate = [];
637
+ let parent = dirname(p), toCreate = [];
638
638
  while (!(yield this._writable.exists(parent, cred))) {
639
639
  toCreate.push(parent);
640
- parent = path.dirname(parent);
640
+ parent = dirname(parent);
641
641
  }
642
642
  toCreate = toCreate.reverse();
643
643
  for (const p of toCreate) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import { Cred } from '../cred.js';
3
- import { File, FileFlag, PreloadFile } from '../file.js';
3
+ import { FileFlag, PreloadFile } from '../file.js';
4
4
  import { SynchronousFileSystem } from '../filesystem.js';
5
5
  import { Stats } from '../stats.js';
6
6
  /**
@@ -126,7 +126,7 @@ export interface SyncKeyValueFileSystemOptions {
126
126
  */
127
127
  supportLinks?: boolean;
128
128
  }
129
- export declare class SyncKeyValueFile extends PreloadFile<SyncKeyValueFileSystem> implements File {
129
+ export declare class SyncKeyValueFile extends PreloadFile<SyncKeyValueFileSystem> {
130
130
  constructor(_fs: SyncKeyValueFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Buffer);
131
131
  syncSync(): void;
132
132
  closeSync(): void;
@@ -156,8 +156,8 @@ export declare class SyncKeyValueFileSystem extends SynchronousFileSystem {
156
156
  accessSync(p: string, mode: number, cred: Cred): void;
157
157
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
158
158
  statSync(p: string, cred: Cred): Stats;
159
- createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): File;
160
- openFileSync(p: string, flag: FileFlag, cred: Cred): File;
159
+ createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): SyncKeyValueFile;
160
+ openFileSync(p: string, flag: FileFlag, cred: Cred): SyncKeyValueFile;
161
161
  unlinkSync(p: string, cred: Cred): void;
162
162
  rmdirSync(p: string, cred: Cred): void;
163
163
  mkdirSync(p: string, mode: number, cred: Cred): void;
@@ -1,4 +1,4 @@
1
- import * as path from 'path';
1
+ import { dirname, basename, join, resolve, sep } from '../emulation/path.js';
2
2
  import { ApiError, ErrorCode } from '../ApiError.js';
3
3
  import { W_OK, R_OK } from '../emulation/constants.js';
4
4
  import { FileFlag, PreloadFile } from '../file.js';
@@ -143,7 +143,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
143
143
  }
144
144
  }
145
145
  renameSync(oldPath, newPath, cred) {
146
- const tx = this.store.beginTransaction('readwrite'), oldParent = path.dirname(oldPath), oldName = path.basename(oldPath), newParent = path.dirname(newPath), newName = path.basename(newPath),
146
+ const tx = this.store.beginTransaction('readwrite'), oldParent = dirname(oldPath), oldName = basename(oldPath), newParent = dirname(newPath), newName = basename(newPath),
147
147
  // Remove oldPath from parent's directory listing.
148
148
  oldDirNode = this.findINode(tx, oldParent), oldDirList = this.getDirListing(tx, oldParent, oldDirNode);
149
149
  if (!oldDirNode.toStats().hasAccess(W_OK, cred)) {
@@ -263,7 +263,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
263
263
  // update is required.
264
264
  const tx = this.store.beginTransaction('readwrite'),
265
265
  // We use the _findInode helper because we actually need the INode id.
266
- fileInodeId = this._findINode(tx, path.dirname(p), path.basename(p)), fileInode = this.getINode(tx, p, fileInodeId), inodeChanged = fileInode.update(stats);
266
+ fileInodeId = this._findINode(tx, dirname(p), basename(p)), fileInode = this.getINode(tx, p, fileInodeId), inodeChanged = fileInode.update(stats);
267
267
  try {
268
268
  // Sync data.
269
269
  tx.put(fileInode.id, data, true);
@@ -303,7 +303,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
303
303
  * @return string The ID of the file's inode in the file system.
304
304
  */
305
305
  _findINode(tx, parent, filename, visited = new Set()) {
306
- const currentPath = path.posix.join(parent, filename);
306
+ const currentPath = join(parent, filename);
307
307
  if (visited.has(currentPath)) {
308
308
  throw new ApiError(ErrorCode.EIO, 'Infinite loop detected while finding inode', currentPath);
309
309
  }
@@ -316,7 +316,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
316
316
  return dirList[filename];
317
317
  }
318
318
  else {
319
- throw ApiError.ENOENT(path.resolve(parent, filename));
319
+ throw ApiError.ENOENT(resolve(parent, filename));
320
320
  }
321
321
  };
322
322
  if (parent === '/') {
@@ -330,7 +330,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
330
330
  }
331
331
  }
332
332
  else {
333
- return readDirectory(this.getINode(tx, parent + path.sep + filename, this._findINode(tx, path.dirname(parent), path.basename(parent), visited)));
333
+ return readDirectory(this.getINode(tx, parent + sep + filename, this._findINode(tx, dirname(parent), basename(parent), visited)));
334
334
  }
335
335
  }
336
336
  /**
@@ -340,7 +340,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
340
340
  * @todo memoize/cache
341
341
  */
342
342
  findINode(tx, p) {
343
- return this.getINode(tx, p, this._findINode(tx, path.dirname(p), path.basename(p)));
343
+ return this.getINode(tx, p, this._findINode(tx, dirname(p), basename(p)));
344
344
  }
345
345
  /**
346
346
  * Given the ID of a node, retrieves the corresponding Inode.
@@ -400,7 +400,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
400
400
  * @return The Inode for the new file.
401
401
  */
402
402
  commitNewFile(tx, p, type, mode, cred, data) {
403
- const parentDir = path.dirname(p), fname = path.basename(p), parentNode = this.findINode(tx, parentDir), dirListing = this.getDirListing(tx, parentDir, parentNode), currTime = new Date().getTime();
403
+ const parentDir = dirname(p), fname = basename(p), parentNode = this.findINode(tx, parentDir), dirListing = this.getDirListing(tx, parentDir, parentNode), currTime = new Date().getTime();
404
404
  //Check that the creater has correct access
405
405
  if (!parentNode.toStats().hasAccess(0b0100 /* Write */, cred)) {
406
406
  throw ApiError.EACCES(p);
@@ -440,7 +440,7 @@ export class SyncKeyValueFileSystem extends SynchronousFileSystem {
440
440
  * @todo Update mtime.
441
441
  */
442
442
  removeEntry(p, isDir, cred) {
443
- const tx = this.store.beginTransaction('readwrite'), parent = path.dirname(p), parentNode = this.findINode(tx, parent), parentListing = this.getDirListing(tx, parent, parentNode), fileName = path.basename(p);
443
+ const tx = this.store.beginTransaction('readwrite'), parent = dirname(p), parentNode = this.findINode(tx, parent), parentListing = this.getDirListing(tx, parent, parentNode), fileName = basename(p);
444
444
  if (!parentListing[fileName]) {
445
445
  throw ApiError.ENOENT(p);
446
446
  }