X-Git-Url: http://git.pk910.de/?p=phpgitweb.git;a=blobdiff_plain;f=htdocs%2Flib%2FTools.class.php;fp=htdocs%2Flib%2FTools.class.php;h=c0b01b0cd15b406e931145b479073f44b3b0589b;hp=6f28961d8d1612e9c11df2c074e386807b07283d;hb=3225d787391540a52b39a34ca809a71d443b49f0;hpb=96f3e3d16220ee514ee16a43a47f8e669fc25cf0 diff --git a/htdocs/lib/Tools.class.php b/htdocs/lib/Tools.class.php index 6f28961..c0b01b0 100644 --- a/htdocs/lib/Tools.class.php +++ b/htdocs/lib/Tools.class.php @@ -17,25 +17,28 @@ */ class Tools { - const S_IFMT = 170000; - const S_IFGITLINK = 160000; - const S_IFLNK = 120000; - const S_IFREG = 100000; - const S_IFDIR = 40000; - const S_IFINVALID = 30000; - const S_IXUSR = 100; + /* octal constants (sys/stat.h) */ + const S_IFMT = 0170000; + const S_IFGITLINK = 0160000; /* GIT defined */ + const S_IFLNK = 0120000; + const S_IFREG = 0100000; + const S_IFDIR = 0040000; + const S_IPERMS = 0000777; + const S_IXUSR = 0000100; public static function get_filetype($mode, $exec = false) { if(!preg_match('/^[0-7]+$/', $mode)) return $mode; - if(($mode & self::S_IFMT) == S_IFGITLINK) + $mode = octdec($mode); + + if(($mode & self::S_IFMT) == self::S_IFGITLINK) return 'submodule'; - else if(($mode & self::S_IFMT) == S_IFDIR) + else if(($mode & self::S_IFMT) == self::S_IFDIR) return 'directory'; - else if(($mode & self::S_IFMT) == S_IFLNK) + else if(($mode & self::S_IFMT) == self::S_IFLNK) return 'symlink'; - else if(($mode & self::S_IFMT) == S_IFREG) { + else if(($mode & self::S_IFMT) == self::S_IFREG) { if($exec && ($mode & self::S_IXUSR)) return 'executable'; return 'file'; @@ -43,6 +46,16 @@ class Tools { return 'unknown'; } + public static function is_regular_file($mode) { + $mode = octdec($mode); + return (($mode & self::S_IFMT) == self::S_IFREG); + } + + public static function get_file_permissions($mode) { + $mode = octdec($mode); + return sprintf("%04o",($mode & self::S_IPERMS)); + } + public static function age_calculate($last_change) { $result = array(); $now = time();