diff options
author | Tony Wang <wwwjfy@gmail.com> | 2013-08-23 22:54:24 +0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-08-25 15:54:06 -0700 |
commit | 1d67d8ff23669814ed92d5d328a65174bfc72efd (patch) | |
tree | cb80cc56ce83a3e3cdae8dfcef295ec65817ff5c /builtin_test.cpp | |
parent | 9f46881c16af03b52b9daba7c645100f180b7a8f (diff) |
add -O and -G to test command
they are available on Linux and OS X, and now ported to fish
Diffstat (limited to 'builtin_test.cpp')
-rw-r--r-- | builtin_test.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/builtin_test.cpp b/builtin_test.cpp index 1cf79896..2fd3f916 100644 --- a/builtin_test.cpp +++ b/builtin_test.cpp @@ -33,13 +33,15 @@ enum token_t test_bang, // "!", inverts sense test_filetype_b, // "-b", for block special files - test_filetype_c, // "-c" for character special files - test_filetype_d, // "-d" for directories - test_filetype_e, // "-e" for files that exist - test_filetype_f, // "-f" for for regular files - test_filetype_g, // "-g" for set-group-id - test_filetype_h, // "-h" for symbolic links + test_filetype_c, // "-c", for character special files + test_filetype_d, // "-d", for directories + test_filetype_e, // "-e", for files that exist + test_filetype_f, // "-f", for for regular files + test_filetype_G, // "-G", for check effective group id + test_filetype_g, // "-g", for set-group-id + test_filetype_h, // "-h", for symbolic links test_filetype_L, // "-L", same as -h + test_filetype_O, // "-O", for check effective user id test_filetype_p, // "-p", for FIFO test_filetype_S, // "-S", socket @@ -95,9 +97,11 @@ static const struct token_info_t {test_filetype_d, L"-d", UNARY_PRIMARY}, {test_filetype_e, L"-e", UNARY_PRIMARY}, {test_filetype_f, L"-f", UNARY_PRIMARY}, + {test_filetype_G, L"-G", UNARY_PRIMARY}, {test_filetype_g, L"-g", UNARY_PRIMARY}, {test_filetype_h, L"-h", UNARY_PRIMARY}, {test_filetype_L, L"-L", UNARY_PRIMARY}, + {test_filetype_O, L"-O", UNARY_PRIMARY}, {test_filetype_p, L"-p", UNARY_PRIMARY}, {test_filetype_S, L"-S", UNARY_PRIMARY}, {test_filesize_s, L"-s", UNARY_PRIMARY}, @@ -812,25 +816,31 @@ static bool unary_primary_evaluate(test_expressions::token_t token, const wcstri case test_filetype_b: // "-b", for block special files return !wstat(arg, &buf) && S_ISBLK(buf.st_mode); - case test_filetype_c: // "-c" for character special files + case test_filetype_c: // "-c", for character special files return !wstat(arg, &buf) && S_ISCHR(buf.st_mode); - case test_filetype_d: // "-d" for directories + case test_filetype_d: // "-d", for directories return !wstat(arg, &buf) && S_ISDIR(buf.st_mode); - case test_filetype_e: // "-e" for files that exist + case test_filetype_e: // "-e", for files that exist return !wstat(arg, &buf); - case test_filetype_f: // "-f" for for regular files + case test_filetype_f: // "-f", for for regular files return !wstat(arg, &buf) && S_ISREG(buf.st_mode); - case test_filetype_g: // "-g" for set-group-id + case test_filetype_G: // "-G", for check effective group id + return !lwstat(arg, &buf) && getegid() == buf.st_gid; + + case test_filetype_g: // "-g", for set-group-id return !wstat(arg, &buf) && (S_ISGID & buf.st_mode); - case test_filetype_h: // "-h" for symbolic links + case test_filetype_h: // "-h", for symbolic links case test_filetype_L: // "-L", same as -h return !lwstat(arg, &buf) && S_ISLNK(buf.st_mode); + case test_filetype_O: // "-O", for check effective user id + return !lwstat(arg, &buf) && geteuid() == buf.st_uid; + case test_filetype_p: // "-p", for FIFO return !wstat(arg, &buf) && S_ISFIFO(buf.st_mode); |