diff --git a/clite/commands.js b/clite/commands.js index fe2b0ff..b64f36f 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -50,7 +50,7 @@ Options: function writeNodeData(st,fd) { if (long) { - if (st.type == 4) { + if (st.type == stdio.types.FT_LINK) { var d = stdio.readAll(fd); if (!d) d = '?'; @@ -95,7 +95,7 @@ Options: return; } var st = stdio.fstat(fd); - if (!st || st.type != 3) { + if (!st || st.type != stdio.types.FT_DIR) { writeNodeData(st,fd); stdio.close(fd); return; @@ -167,7 +167,7 @@ Options: function fcb(fd) { var st = stdio.fstat(fd); // check if it's a directory or link - if (!st || st.type == 3 || st.type == 4) { + if (!st || st.type == stdio.types.FT_DIR || st.type == stdio.types.FT_LINK) { if (st) { io.error('not a normal file: '+st.name); }else{ @@ -196,16 +196,16 @@ Options: } files.forEach(function(file,index) { - var fd = stdio.open(file,fcb); - if (!fd) { - io.error('cannot open file: '+file); + var st = stdio.stat(file); + // check if it's a directory or link + if (!st || st.type == stdio.types.FT_DIR || st.type == stdio.types.FT_LINK) { + io.error('not a normal file: '+file); pending--; return; } - var st = stdio.fstat(fd); - // check if it's a directory or link - if (!st || st.type == 3 || st.type == 4) { - io.error('not a normal file: '+file); + var fd = stdio.open(file,fcb); + if (!fd) { + io.error('cannot open file: '+file); pending--; return; } diff --git a/clite/core.js b/clite/core.js index 49ed613..f3ed431 100644 --- a/clite/core.js +++ b/clite/core.js @@ -714,6 +714,26 @@ clite.io = { return clite.io.fchmod(fd,mode); } }, + // 0: unknown + // 1: text file + // 2: executable/binary (function) + // 3: directory + // 4: link + // 5: device + // 6: unloaded remote file + // 7: shell script + // 8: image + types:{ + FT_UNKOWN:0, + FT_TEXT:1, + FT_BINARY:2, + FT_DIR:3, + FT_LINK:4, + FT_DEV:5, + FT_REMOTE:6, + FT_SCRIPT:7, + FT_IMAGE:8 + }, creat:null, open:null, close:null, @@ -1633,39 +1653,39 @@ clite.lib = { // 8: image if (fd.node.data.content == null) { if (fd.node.data.remote != null) - return 6; - return 0; + return clite.io.types.FT_REMOTE; + return clite.io.types.FT_UNKOWN; } if (fd.node.data.islink) - return 4; + return clite.io.types.FT_LINK; if (fd.node.data.isdir) - return 3; + return clite.io.types.FT_DIR; if (fd.node.data.isdev) - return 5; + return clite.io.types.FT_DEV; const type = typeof fd.node.data.content; switch (type) { case 'string': // text file if (fd.node.data.content.substring(0,2) == '#!') - return 7; - return 1; + return clite.io.types.FT_SCRIPT; + return clite.io.types.FT_TEXT; break; case 'function': // executable - return 2; + return clite.io.types.FT_BINARY; break; case 'object': if (Array.isArray(fd.node.data.content)) // directory - return 3; + return clite.io.types.FT_DIR; if (fd.node.data.content instanceof HTMLImageElement) - return 8; + return clite.io.types.FT_IMAGE; case 'symbol': case 'boolean': case 'number': case 'bigint': case 'undefined': default: - return 0; + return clite.io.types.FT_UNKOWN; } - return 0; + return clite.io.types.FT_UNKOWN; }, getBuffer:function() { return Object.create({