Skip to content

Commit

Permalink
alias hardlink to symlink (this is wrong)
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerIn-wonderland committed Nov 7, 2024
1 parent 4aac6a0 commit ac895bc
Showing 1 changed file with 1 addition and 49 deletions.
50 changes: 1 addition & 49 deletions src/api/LocalFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,55 +567,7 @@ class LocalFS extends AFSProvider<LocalFSStats> {
await this.promises.saveStats();
},
link: (existingPath: string, newPath: string): Promise<void> => {
existingPath = this.relativizePath(existingPath);
newPath = this.relativizePath(newPath);
return new Promise((resolve, reject) => {
// Check if existingPath exists in the stats
const existingStats = this.stats.get(existingPath);
if (!existingStats) {
return reject({
name: "ENOENT",
code: "ENOENT",
errno: -2,
message: `No such file or directory: ${existingPath}`,
stack: "Error: No such file",
} as Error);
}

// Ensure it's not a directory (as link() doesn't work for directories)
if (existingStats.isDirectory()) {
return reject({
name: "EPERM",
code: "EPERM",
errno: -1,
message: `Operation not permitted: ${existingPath} is a directory`,
stack: "Error: Operation not permitted",
} as Error);
}

// Check if newPath already exists
if (this.stats.has(newPath)) {
return reject({
name: "EEXIST",
code: "EEXIST",
errno: -17,
message: `File already exists: ${newPath}`,
stack: "Error: File exists",
} as Error);
}

// Create a hard link by sharing the same stats object (inode)
this.stats.set(newPath, existingStats);

// Increment the link count for the existing file
existingStats.nlink++;

// Save stats and resolve the promise
this.promises
.saveStats()
.then(() => resolve())
.catch(reject);
});
return this.promises.symlink(existingPath, newPath);
},
lstat: async (path: string) => {
path = this.relativizePath(path);
Expand Down

0 comments on commit ac895bc

Please sign in to comment.