diff --git a/src/parser.js b/src/parser.js index 474e239..859bc53 100644 --- a/src/parser.js +++ b/src/parser.js @@ -24,11 +24,12 @@ * execution is on * T the 1000 bit is turned on, and execution is off (undefined bit- * state) + * . or + indicates whether file has ACL set (http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c?id=v8.21#n3785) */ var RE_UnixEntry = new RegExp( "([bcdlfmpSs-])" - + "(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s+" + + "(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))(?\\+|\\.)?\\s+" + "(\\d+)\\s+" + "(\\S+)\\s+" + "(?:(\\S+)\\s+)?" @@ -183,24 +184,28 @@ var parsers = { if (group) { var type = group[1]; - //var hardLinks = group[15]; - var usr = group[16]; - var grp = group[17]; - var size = group[18]; - var name = group[21]; + + // http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c?id=v8.21#n3785 + var hasACL = group[15] != undefined; + + //var hardLinks = group[16]; + var usr = group[17]; + var grp = group[18]; + var size = group[19]; + var name = group[22]; var date; // Check whether we are given the time (recent file) or the year // (older file) in the file listing. - if (group[20].indexOf(":") === -1) { - date = +new Date(group[19] + " " + group[20]).getTime(); + if (group[21].indexOf(":") === -1) { + date = +new Date(group[20] + " " + group[21]).getTime(); } else { var currentMonth = new Date().getMonth(); - var month = new Date(group[19]).getMonth(); + var month = new Date(group[20]).getMonth(); var year = new Date().getFullYear() - (currentMonth < month ? 1 : 0); - date = +new Date(group[19] + " " + group[20] + " " + year); + date = +new Date(group[20] + " " + group[21] + " " + year); } // Ignoring '.' and '..' entries for now @@ -208,7 +213,7 @@ var parsers = { return; } - //var endtoken = group[22]; + //var endtoken = group[23]; switch (type[0]) { case 'd': @@ -239,7 +244,8 @@ var parsers = { time: date, size: size, owner: usr, - group: grp + group: grp, + hasACL: hasACL, }; if (target) file.target = target; diff --git a/test/parser.test.js b/test/parser.test.js index 2684c56..d86e94a 100644 --- a/test/parser.test.js +++ b/test/parser.test.js @@ -108,20 +108,20 @@ drwx------ 2 1001 1001 4096 Oct 19 16:17 project2\r\n"; time: +new Date("Oct 19 16:17 " + new Date().getFullYear()), owner: "1001", group: "1001", - + userReadPerm: true, userWritePerm: true, userExecPerm: true, - + groupReadPerm: false, groupWritePerm: false, groupExecPerm: false, - + otherReadPerm: false, otherWritePerm: false, otherExecPerm: false } - ]; + ]; Parser.parseEntries(str, function(err, entryArray) { entryArray.forEach(function(entry, i) { @@ -143,6 +143,8 @@ drwx------ 2 1001 1001 4096 Oct 19 16:17 project2\r\n"; assert.equal(unixEntries[i].otherReadPerm, entry.otherPermissions.read); assert.equal(unixEntries[i].otherWritePerm, entry.otherPermissions.write); assert.equal(unixEntries[i].otherExecPerm, entry.otherPermissions.exec); + + assert.equal(unixEntries[i].hasACL, entry.otherPermissions.hasACL); }); }) }); @@ -591,6 +593,85 @@ drwx------ 2 1001 1001 4096 Oct 19 16:17 project2\r\n"; }) }); + it("test unix extended attributes responses", function() { + var str = "-rwx--x--- 10 mrclash adm 4096 Aug 9 14:48 noExtendedAttributes\r\n\ +-rwx--x---. 10 mrclash adm 4096 Aug 9 14:48 withExtendedAttributes\r\n"; + + var unixEntries = [ + { + //line: "drwx--x--- 10 mrclash adm 4096 Aug 9 14:48 noExtendedAttributes", + type: 0, + size: 4096, + name: "noExtendedAttributes", + time: +new Date("Mar 9 2008"), + owner: "mrclash", + group: "adm", + + userReadPerm: true, + userWritePerm: true, + userExecPerm: true, + + groupReadPerm: false, + groupWritePerm: false, + groupExecPerm: true, + + otherReadPerm: false, + otherWritePerm: false, + otherExecPerm: false, + + hasACL: false, + }, + { + //line: "drwx--x--- 10 mrclash adm 4096 Aug 9 14:48 withExtendedAttributes", + type: 0, + size: 4096, + name: "withExtendedAttributes", + time: +new Date("Aug 9 2010"), + owner: "mrclash", + group: "adm", + + userReadPerm: true, + userWritePerm: true, + userExecPerm: true, + + groupReadPerm: false, + groupWritePerm: false, + groupExecPerm: true, + + otherReadPerm: false, + otherWritePerm: false, + otherExecPerm: false, + + hasACL: true, + }, + ]; + + Parser.parseEntries(str, function(err, entryArray) { + entryArray.forEach(function(entry, i) { + assert.equal(unixEntries[i].type, entry.type); + assert.equal(unixEntries[i].size, entry.size); + assert.equal(unixEntries[i].name, entry.name); + //assert.equal(unixEntries[i].time, entry.time); + assert.equal(unixEntries[i].owner, entry.owner); + assert.equal(unixEntries[i].group, entry.group); + + assert.equal(unixEntries[i].userReadPerm, entry.userPermissions.read); + assert.equal(unixEntries[i].userWritePerm, entry.userPermissions.write); + assert.equal(unixEntries[i].userExecPerm, entry.userPermissions.exec); + + assert.equal(unixEntries[i].groupReadPerm, entry.groupPermissions.read); + assert.equal(unixEntries[i].groupWritePerm, entry.groupPermissions.write); + assert.equal(unixEntries[i].groupExecPerm, entry.groupPermissions.exec); + + assert.equal(unixEntries[i].otherReadPerm, entry.otherPermissions.read); + assert.equal(unixEntries[i].otherWritePerm, entry.otherPermissions.write); + assert.equal(unixEntries[i].otherExecPerm, entry.otherPermissions.exec); + + assert.equal(unixEntries[i].hasACL, entry.hasACL); + }); + }) + }); + it("test ftp windows/DOS LIST responses", function() { var dosEntries = [