Package org.jruby.util

Examples of org.jruby.util.JRubyFile


    public static IRubyObject rmdir19(ThreadContext context, IRubyObject recv, IRubyObject path) {
        return rmdirCommon(context.getRuntime(), getPath19(context, path));
    }

    private static IRubyObject rmdirCommon(Ruby runtime, String path) {
        JRubyFile directory = getDir(runtime, path, true);

        if (!directory.delete()) {
            throw runtime.newSystemCallError("No such directory");
        }

        return runtime.newFixnum(0);
    }
View Full Code Here


            } else {
                throw runtime.newErrnoENOTDIRError(dir + " is not a directory");
            }
        }

        JRubyFile result = JRubyFile.create(runtime.getCurrentDirectory(), dir);

        if (mustExist && !result.exists()) {
            throw runtime.newErrnoENOENTError("No such file or directory - " + dir);
        }

        boolean isDirectory = result.isDirectory();

        if (mustExist && !isDirectory) {
            throw runtime.newErrnoENOTDIRError(path + " is not a directory");
        }
View Full Code Here

        if (path.equals("/dev/null") || path.equalsIgnoreCase("nul:") || path.equalsIgnoreCase("nul")) {
            descriptor = descriptor.reopen(new NullChannel(), modes);
        } else {
            String cwd = runtime.getCurrentDirectory();
            JRubyFile theFile = JRubyFile.create(cwd,path);

            if (theFile.isDirectory() && modes.isWritable()) throw new DirectoryAsFileException();

            if (modes.isCreate()) {
                if (theFile.exists() && modes.isExclusive()) {
                    throw runtime.newErrnoEEXISTError("File exists - " + path);
                }
                theFile.createNewFile();
            } else {
                if (!theFile.exists()) {
                    throw runtime.newErrnoENOENTError("file not found - " + path);
                }
            }

            // We always open this rw since we can only open it r or rw.
View Full Code Here

        Ruby runtime = context.getRuntime();
       
        int count = 0;
        RubyInteger mode = args[0].convertToInteger();
        for (int i = 1; i < args.length; i++) {
            JRubyFile filename = file(args[i]);
           
            if (!filename.exists()) {
                throw runtime.newErrnoENOENTError(filename.toString());
            }
           
            boolean result = 0 == runtime.getPosix().chmod(filename.getAbsolutePath(), (int)mode.getLongValue());
            if (result) {
                count++;
            }
        }
       
View Full Code Here

        int group = -1;
        if (!args[1].isNil()) {
            group = RubyNumeric.num2int(args[1]);
        }
        for (int i = 2; i < args.length; i++) {
            JRubyFile filename = file(args[i]);

            if (!filename.exists()) {
                throw runtime.newErrnoENOENTError(filename.toString());
            }
           
            boolean result = 0 == runtime.getPosix().chown(filename.getAbsolutePath(), owner, group);
            if (result) {
                count++;
            }
        }
       
View Full Code Here

            } else if (cwd.length() > 0 && cwd.charAt(0) == '/') {
                padSlashes = countSlashes(cwd);
            }
        }
       
        JRubyFile path;
       
        if (relativePath.length() == 0) {
            path = JRubyFile.create(relativePath, cwd);
        } else {
            relativePath = adjustRootPathOnWindows(runtime, relativePath, cwd);
            path = JRubyFile.create(cwd, relativePath);
        }

        return runtime.newString(padSlashes + canonicalize(path.getAbsolutePath()));
    }
View Full Code Here

        runtime.checkSafeString(oldNameString);
        runtime.checkSafeString(newNameString);

        String newNameJavaString = newNameString.getUnicodeValue();
        String oldNameJavaString = oldNameString.getUnicodeValue();
        JRubyFile oldFile = JRubyFile.create(runtime.getCurrentDirectory(), oldNameJavaString);
        JRubyFile newFile = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString);
       
        if (!oldFile.exists() || !newFile.getParentFile().exists()) {
            throw runtime.newErrnoENOENTError(oldNameJavaString + " or " + newNameJavaString);
        }

        JRubyFile dest = JRubyFile.create(runtime.getCurrentDirectory(), newNameJavaString);

        if (oldFile.renameTo(dest)) {  // rename is successful
            return RubyFixnum.zero(runtime);
        }
View Full Code Here

        for (int i = 2, j = args.length; i < j; i++) {
            RubyString filename = get_path(context, args[i]);
            runtime.checkSafeString(filename);
           
            JRubyFile fileToTouch = JRubyFile.create(runtime.getCurrentDirectory(),filename.getUnicodeValue());
           
            if (!fileToTouch.exists()) {
                throw runtime.newErrnoENOENTError(filename.toString());
            }

            runtime.getPosix().utimes(fileToTouch.getAbsolutePath(), atimeval, mtimeval);
        }
       
        return runtime.newFixnum(args.length - 2);
    }
View Full Code Here

        Ruby runtime = context.getRuntime();
        
        for (int i = 0; i < args.length; i++) {
            RubyString filename = get_path(context, args[i]);
            runtime.checkSafeString(filename);
            JRubyFile lToDelete = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue());
           
            boolean isSymlink = RubyFileTest.symlink_p(recv, filename).isTrue();
            // Broken symlinks considered by exists() as non-existing,
            // so we need to check for symlinks explicitly.
            if (!lToDelete.exists() && !isSymlink) {
                throw runtime.newErrnoENOENTError(filename.getUnicodeValue());
            }

            if (lToDelete.isDirectory() && !isSymlink) {
                throw runtime.newErrnoEPERMError(filename.getUnicodeValue());
            }

            if (!lToDelete.delete()) {
                throw runtime.newErrnoEACCESError(filename.getUnicodeValue());
            }
        }
       
        return runtime.newFixnum(args.length);
View Full Code Here

        return timeval;
    }

    // Fast path since JNA stat is about 10x slower than this
    private static IRubyObject getLastModified(Ruby runtime, String path) {
        JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(), path);
       
        if (!file.exists()) {
            throw runtime.newErrnoENOENTError(path);
        }
       
        return runtime.newTime(file.lastModified());
    }
View Full Code Here

TOP

Related Classes of org.jruby.util.JRubyFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.