public static void matchesFilePermissions ( String filename , PosixFilePermission p ) throws IOException { filenameSanityChecks ( filename ) ; if ( p == null ) throw new NullPointerException ( "null permission passed as argument" ) ; File f = new File ( filename ) ; // Don't get fooled by symlinks... String canonicalPath = f . getCanonicalPath ( ) ; String filePerms = getFilePermissions ( canonicalPath ) ; if ( ! filePerms . startsWith ( p . statForm ) ) throw new FilePermissionError ( "Wrong file permissions on file " + filename + ". Required permissions are: " + p . chmodForm ( ) ) ; }
Checks that a given file has the appropriate unix permissions . This naive implementation just fetches the output of ls - al on a given file and matches the resulting string with the permissionString passed as argument .