private void setup(String filename, boolean lstat) { if (Platform.IS_WINDOWS && filename.length() == 2 && filename.charAt(1) == ':' && Character.isLetter(filename.charAt(0))) { filename += "/"; } file = JRubyFile.create(getRuntime().getCurrentDirectory(), filename); if (lstat) { stat = getRuntime().getPosix().lstat(file.getAbsolutePath()); } else { stat = getRuntime().getPosix().stat(file.getAbsolutePath()); } }
/** * Чтение информации о файле * <br>Генерирует StdErr в случаи ошибки * @param filename Файл * @return информация о файле, размер, тип, владелец .... * @see xyz.cofe.unix.libc.StdErr */ public FileStat lstat( String filename ){ if( filename==null )throw new IllegalArgumentException( "filename==null" ); org.jruby.ext.posix.FileStat fstat = null; synchronized( syncObj ){ fstat = posix.lstat(filename); if( fstat==null ){ int errno = posix.errno(); throw new StdErr(errno, LibC.strerror(errno)); } // if( fstat.mode()==0 ){ // int errno = posix.errno(); // throw new StdErr(errno, LibC.strerror(errno)); // } } return new LinuxFileStatImpl(fstat); } //</editor-fold>
@JRubyMethod(name = "symlink?", required = 1, module = true) public static RubyBoolean symlink_p(IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); JRubyFile file = file(filename); try { // Note: We can't use file.exists() to check whether the symlink // exists or not, because that method returns false for existing // but broken symlink. So, we try without the existence check, // but in the try-catch block. // MRI behavior: symlink? on broken symlink should return true. return runtime.newBoolean(runtime.getPosix().lstat(file.getAbsolutePath()).isSymlink()); } catch (RaiseException re) { return runtime.getFalse(); } }