Skip to content

Commit

Permalink
Fix symlink (16) and renameat (74)
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerIn-wonderland committed Jul 28, 2024
1 parent 7848937 commit e275c37
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions lib/9p-filer.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,23 @@ Virtio9p.prototype.ReceiveRequest = async function(bufchain) {
var name = req[1];
var newPath = Path.join(path, name);
var symtgt = req[2];
var symtgtPath = Path.join(path, symtgt);
// TODO: deal with gid
var gid = req[3];
console.log(self.fids[fid]);
console.log(req);

message.Debug("[symlink] fid=" + fid + ", name=" + name + ", symtgt=" + symtgt + ", gid=" + gid);

fs.symlink(symtgt, newPath, function(err) {
console.log("[symlink] fid=" + fid + ", name=" + name + ", symtgt=" + symtgt + ", gid=" + gid);
fs.symlink(Path.resolve(path, name), Path.resolve(path, symtgt), function(err) {
if (self.shouldAbortRequest(tag)) return;

if (err) {
self.SendError(tag, err);
self.SendReply(bufchain);
return;
}
fs.stat(newPath, function(err, stats) {
fs.stat(newPath, function(err, stats) {
if (self.shouldAbortRequest(tag)) return;

if (err) {
Expand Down Expand Up @@ -1041,18 +1044,43 @@ Virtio9p.prototype.ReceiveRequest = async function(bufchain) {
var newPath = Path.join(self.fids[newdirfid].path, newname);
message.Debug("[renameat]: oldname=" + oldname + " newname=" + newname);

fs.rename(oldPath, newPath, function(err) {
if (self.shouldAbortRequest(tag)) return;

if (err) {
self.SendError(tag, err);
self.SendReply(bufchain);
fs.exists(newPath, (exists) => {
if (exists) {
(new fs.Shell()).rm(newPath, {recursive: true}, (err) => {
if (err) {
self.SendError(tag, err);
self.SendReply(bufchain);
} else {
fs.rename(oldPath, newPath, function(err) {
if (self.shouldAbortRequest(tag)) return;

if (err) {
self.SendError(tag, err);
self.SendReply(bufchain);
}

self.BuildReply(id, tag, 0);
self.SendReply(bufchain);
});
}

});
} else {
fs.rename(oldPath, newPath, function(err) {
if (self.shouldAbortRequest(tag)) return;

if (err) {
self.SendError(tag, err);
self.SendReply(bufchain);
}


self.BuildReply(id, tag, 0);
self.SendReply(bufchain);
});
}


self.BuildReply(id, tag, 0);
self.SendReply(bufchain);
});

})

break;

Expand Down

0 comments on commit e275c37

Please sign in to comment.