remove getFileType from stdlib

This commit is contained in:
Lisa Milne 2023-11-21 14:05:09 +10:00
parent e8ef43130a
commit 4803cf8e13
3 changed files with 36 additions and 40 deletions

View file

@ -333,8 +333,8 @@ Options:
io.exit(1);
return;
}
var t = stdlib.getFileType(fd);
if (t != 1 && t != 7) {
var st = stdio.fstat(fd);
if ( !st || (st.type != stdio.types.FT_TEXT && st.type != stdio.types.FT_SCRIPT)) {
io.error('can not read files of this type');
io.exit(1);
return;
@ -475,38 +475,42 @@ Options:
return 1;
}
var t = stdlib.getFileType(fd);
var st = stdio.fstat(fd);
stdio.close(fd);
var txt = short+': ';
switch (t) {
case 1:
txt += 'Plain Text';
break;
case 2:
txt += 'CLIte Executable';
break;
case 3:
txt += 'Directory';
break;
case 4:
txt += 'Link';
break;
case 5:
txt += 'Device File';
break;
case 6:
txt += 'Unloaded Remote Data';
break;
case 7:
txt += 'Shell Script';
break;
case 8:
txt += 'Image';
break;
default:
txt += 'Unknown Data';
break;
if (!st) {
txt += 'Unknown';
}else{
switch (st.type) {
case stdio.types.FT_TEXT:
txt += 'Plain Text';
break;
case stdio.types.FT_BINARY:
txt += 'CLIte Executable';
break;
case stdio.types.FT_DIR:
txt += 'Directory';
break;
case stdio.types.FT_LINK:
txt += 'Link';
break;
case stdio.types.FT_DEV:
txt += 'Device File';
break;
case stdio.types.FT_REMOTE:
txt += 'Unloaded Remote Data';
break;
case stdio.types.FT_SCRIPT:
txt += 'Shell Script';
break;
case stdio.types.FT_IMAGE:
txt += 'Image';
break;
default:
txt += 'Unknown Data';
break;
}
}
io.write(txt);

View file

@ -1831,7 +1831,6 @@ clite.lib.api = { // this is passed to programs via include('stdlib')
basename:clite.lib.basename,
dirname:clite.lib.dirname,
resolvePath:clite.lib.resolvePath,
getFileType:clite.lib.getFileType,
strToArgs:clite.lib.strToArgs,
fork:clite.lib.fork,
exec:clite.lib.exec

View file

@ -152,12 +152,6 @@ stdlib: io.include('stdlib')
resolvePath('file.txt','/etc') -> '/etc/file.txt'
resolvePath('~/../file.txt') -> '/usr/home/file.txt'
getFileType(fd)
special function that returns the type of file that a file
descriptor refers to. See stdio.types for return values.
Likely to be removed, as stdio.stat('path') or stdio.fstat(fd)
includes this data.
strToArgs('string')
special function that splits a string into an array of arguments
for passing to exec(), supports quotes and so on:
@ -173,8 +167,7 @@ stdio: io.include('stdio')
Provides access to io functions and types for file access
stdio.types:
object for mapping return values of stdlib.getFileType() or values of
stat.type:
object for mapping values of stat.type:
FT_UNKOWN: 0 Unknown file type
FT_TEXT: 1 Plain text file
FT_BINARY: 2 Binary file, likely a javascript function