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=6f28961d8d1612e9c11df2c074e386807b07283d;hp=d7f9075bff8522dabfc6525cdda50009cea3edae;hb=96f3e3d16220ee514ee16a43a47f8e669fc25cf0;hpb=27626297549b51277777302328ce6e793b6e5e17 diff --git a/htdocs/lib/Tools.class.php b/htdocs/lib/Tools.class.php index d7f9075..6f28961 100644 --- a/htdocs/lib/Tools.class.php +++ b/htdocs/lib/Tools.class.php @@ -17,6 +17,31 @@ */ 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; + + public static function get_filetype($mode, $exec = false) { + if(!preg_match('/^[0-7]+$/', $mode)) + return $mode; + + if(($mode & self::S_IFMT) == S_IFGITLINK) + return 'submodule'; + else if(($mode & self::S_IFMT) == S_IFDIR) + return 'directory'; + else if(($mode & self::S_IFMT) == S_IFLNK) + return 'symlink'; + else if(($mode & self::S_IFMT) == S_IFREG) { + if($exec && ($mode & self::S_IXUSR)) + return 'executable'; + return 'file'; + } else + return 'unknown'; + } public static function age_calculate($last_change) { $result = array();