Identify type of failure for fs.Rename using -errno convention
This commit is contained in:
parent
c66731d55d
commit
3fe75a9130
|
@ -587,8 +587,11 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
var newname = req[3];
|
||||
message.Debug("[renameat]: oldname=" + oldname + " newname=" + newname);
|
||||
var ret = this.fs.Rename(this.fids[olddirfid].inodeid, oldname, this.fids[newdirfid].inodeid, newname);
|
||||
if (ret == false) {
|
||||
this.SendError(tag, "No such file or directory", ENOENT);
|
||||
if (ret < 0) {
|
||||
let error_message = "";
|
||||
if(ret === -ENOENT) error_message = "No such file or directory";
|
||||
else if(ret === -EPERM) error_message = "Operation not permitted";
|
||||
this.SendError(tag, error_message, -ret);
|
||||
this.SendReply(bufchain);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -731,15 +731,18 @@ FS.prototype.CloseInode = function(id) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {number} 0 if success, or -errno if failured.
|
||||
*/
|
||||
FS.prototype.Rename = function(olddirid, oldname, newdirid, newname) {
|
||||
// message.Debug("Rename " + oldname + " to " + newname);
|
||||
if ((olddirid == newdirid) && (oldname == newname)) {
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
var oldid = this.Search(olddirid, oldname);
|
||||
if(oldid === -1)
|
||||
{
|
||||
return false;
|
||||
return -ENOENT;
|
||||
}
|
||||
var oldpath = this.GetFullPath(oldid);
|
||||
|
||||
|
@ -770,17 +773,17 @@ FS.prototype.Rename = function(olddirid, oldname, newdirid, newname) {
|
|||
{
|
||||
// Move inode within the same child filesystem.
|
||||
|
||||
const success = this.follow_fs(olddir)
|
||||
const ret = this.follow_fs(olddir)
|
||||
.Rename(olddir.foreign_id, oldname, newdir.foreign_id, newname);
|
||||
|
||||
if(!success) return false;
|
||||
if(ret < 0) return ret;
|
||||
}
|
||||
else if(this.GetInode(idx).parentid === -1)
|
||||
{
|
||||
// The actual inode is a root of some descendant filesystem.
|
||||
// Moving mountpoint across fs not supported - needs to update all corresponding forwarders.
|
||||
dbg_log("XXX: Attempted to move mountpoint (" + oldname + ") - skipped", LOG_9P);
|
||||
return false;
|
||||
return -EPERM;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -836,20 +839,20 @@ FS.prototype.Rename = function(olddirid, oldname, newdirid, newname) {
|
|||
{
|
||||
for(const child_filename of this.GetChildren(diverted_old_idx))
|
||||
{
|
||||
const success = this.Rename(diverted_old_idx, child_filename, idx, child_filename);
|
||||
if(!success) return false;
|
||||
const ret = this.Rename(diverted_old_idx, child_filename, idx, child_filename);
|
||||
if(ret < 0) return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform destructive changes only after migration succeeded.
|
||||
this.DeleteData(diverted_old_idx);
|
||||
const success = this.Unlink(diverted_old_idx);
|
||||
if(!success) return false;
|
||||
const ret = this.Unlink(diverted_old_idx);
|
||||
if(ret < 0) return ret;
|
||||
}
|
||||
|
||||
this.NotifyListeners(idx, "rename", {oldpath: oldpath});
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
};
|
||||
|
||||
FS.prototype.Write = function(id, offset, count, buffer) {
|
||||
|
|
Loading…
Reference in a new issue