mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
modify stat/fstat to stat/lstat/fstatat
This commit is contained in:
parent
d2ba616d4f
commit
8eb92af201
3 changed files with 34 additions and 18 deletions
|
|
@ -109,7 +109,7 @@ Options:
|
|||
stdio.write(io.stderr,'cannot open directory: '+dir);
|
||||
return;
|
||||
}
|
||||
var st = stdio.fstat(fd);
|
||||
var st = stdio.fstatat(fd,stdio.flags.AT_SYMLINK_NOFOLLOW);
|
||||
if (!st) {
|
||||
stdio.write(io.stderr,'cannot read file: '+dir);
|
||||
stdio.close(fd);
|
||||
|
|
@ -129,7 +129,7 @@ Options:
|
|||
stdio.write(io.stderr,'cannot read contents: '+dir);
|
||||
break;
|
||||
}
|
||||
var est = stdio.fstat(efd);
|
||||
var est = stdio.fstatat(efd,stdio.flags.AT_SYMLINK_NOFOLLOW);
|
||||
if (!est) {
|
||||
stdio.close(efd);
|
||||
stdio.write(io.stderr,'cannot read content: '+dir);
|
||||
|
|
@ -200,7 +200,7 @@ Options:
|
|||
}
|
||||
|
||||
function fcb(fd) {
|
||||
var st = stdio.fstat(fd);
|
||||
var st = stdio.fstatat(fd,stdio.flags.AT_SYMLINK_NOFOLLOW);
|
||||
// check if it's a directory or link
|
||||
if (
|
||||
!st
|
||||
|
|
@ -386,10 +386,10 @@ Options:
|
|||
io.exit(1);
|
||||
return;
|
||||
}
|
||||
var st = stdio.fstat(fd);
|
||||
var st = stdio.fstatat(fd,0);
|
||||
if ( !st || (st.type != stdio.types.FT_TEXT && st.type != stdio.types.FT_SCRIPT)) {
|
||||
stdio.write(io.stderr,'can not read files of this type');
|
||||
io.exit(1);
|
||||
io.exit(1);
|
||||
return;
|
||||
}
|
||||
var txt = stdio.readAll(fd);
|
||||
|
|
@ -544,7 +544,7 @@ Options:
|
|||
}
|
||||
|
||||
function removeFile(path) {
|
||||
var st = stdio.stat(path);
|
||||
var st = stdio.lstat(path);
|
||||
if (!st) {
|
||||
if (force)
|
||||
return 0;
|
||||
|
|
@ -642,7 +642,7 @@ Options:
|
|||
return 1;
|
||||
}
|
||||
|
||||
var st = stdio.stat(file);
|
||||
var st = stdio.lstat(file);
|
||||
if (st) {
|
||||
stdio.fprintf(io.stderr,'already exists: %s\n',short);
|
||||
return 1;
|
||||
|
|
@ -965,7 +965,7 @@ Options:
|
|||
return 1;
|
||||
}
|
||||
|
||||
var st = stdio.stat(file);
|
||||
var st = stdio.lstat(file);
|
||||
if (!st) {
|
||||
stdio.fprintf(io.stderr,'cannot open file: %s\n',short);
|
||||
return 1;
|
||||
|
|
@ -1022,7 +1022,7 @@ Options:
|
|||
return 1;
|
||||
}
|
||||
|
||||
var st = stdio.stat(file);
|
||||
var st = stdio.lstat(file);
|
||||
|
||||
var txt = short+': ';
|
||||
if (!st) {
|
||||
|
|
|
|||
|
|
@ -1366,7 +1366,12 @@ clite.io = {
|
|||
var uid = clite.proc.getUID(pid);
|
||||
return vfsapi.mkLink(uid,path,target);
|
||||
},
|
||||
clite.io.fstat = function(pid,fd) {
|
||||
clite.io.fstatat = function(pid,fd,flags) {
|
||||
if (!fd || !fd.node || !fd.canread)
|
||||
return null;
|
||||
|
||||
if (fd.node.islink && (flags&clite.io.flags.AT_SYMLINK_NOFOLLOW) == 0)
|
||||
fd = getFileDesPre(pid,n.node.data.content,true);
|
||||
if (!fd || !fd.node || !fd.canread)
|
||||
return null;
|
||||
|
||||
|
|
@ -1384,10 +1389,6 @@ clite.io = {
|
|||
|
||||
return stat;
|
||||
},
|
||||
clite.io.stat = function(pid,path) {
|
||||
var fd = getFileDes(pid,path,true,false);
|
||||
return clite.io.fstat(pid,fd);
|
||||
},
|
||||
clite.io.fchmod = function(pid,fd,mode) {
|
||||
var uid = clite.proc.getUID(pid);
|
||||
if (fd.node.uid != uid)
|
||||
|
|
@ -1827,6 +1828,7 @@ clite.io = {
|
|||
O_EXCL: parseInt('0x000010',16), // if O_CREAT is set, fail if file exists
|
||||
O_NOCTTY: parseInt('0x0',16), // no op
|
||||
O_NOFOLLOW: parseInt('0x000020',16), // if file is a symlink, don't follow it
|
||||
AT_SYMLINK_NOFOLLOW: parseInt('0x000020',16), // if file is a symlink, don't follow it
|
||||
O_NONBLOCK: parseInt('0x000040',16), // no callbacks, return immediately
|
||||
O_SYNC: parseInt('0x000080',16), // write immediately (may fail on remote data)
|
||||
O_TRUNC: parseInt('0x000100',16), // set file size to 0 before writing, requires O_RDWR or O_WRONLY
|
||||
|
|
|
|||
|
|
@ -55,12 +55,26 @@ return Object.create({
|
|||
return clite.io.link(io.pid,path,target);
|
||||
},
|
||||
|
||||
stat:function(path) {
|
||||
return clite.io.stat(io.pid,path);
|
||||
fstatat:function(fd,flags) {
|
||||
return clite.io.fstatat(io.pid,fd,flags);
|
||||
},
|
||||
|
||||
fstat:function(fd) {
|
||||
return clite.io.fstat(io.pid,fd);
|
||||
stat:function(path) {
|
||||
var fd = clite.io.open(io.pid,path,clite.io.flags.O_RDONLY);
|
||||
if (!fd)
|
||||
return null;
|
||||
var st = clite.io.fstatat(io.pid,fd,0);
|
||||
clite.io.close(io.pid,fd);
|
||||
return st;
|
||||
},
|
||||
|
||||
lstat:function(path) {
|
||||
var fd = clite.io.open(io.pid,path,clite.io.flags.O_RDONLY|clite.io.flags.O_NOFOLLOW);
|
||||
if (!fd)
|
||||
return null;
|
||||
var st = clite.io.fstatat(io.pid,fd,clite.io.flags.AT_SYMLINK_NOFOLLOW);
|
||||
clite.io.close(io.pid,fd);
|
||||
return st;
|
||||
},
|
||||
|
||||
chmod:function(path,mode) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue