Package jnr.posix

Examples of jnr.posix.FileStat


        return length > 0 ? runtime.newFixnum(length) : runtime.getNil();
    }

    @JRubyMethod(name = "socket?", required = 1, module = true)
    public static IRubyObject socket_p(IRubyObject recv, IRubyObject filename) {
        FileStat stat = fileResource(filename).stat();

        return recv.getRuntime().newBoolean(stat != null && stat.isSocket());
    }
View Full Code Here


        return recv.getRuntime().newBoolean(stat != null && stat.isSocket());
    }

    @JRubyMethod(name = "sticky?", required = 1, module = true)
    public static IRubyObject sticky_p(IRubyObject recv, IRubyObject filename) {
        FileStat stat = fileResource(filename).stat();

        return recv.getRuntime().newBoolean(stat != null && stat.isSticky());
    }
View Full Code Here

            // 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.
            FileStat stat = fileResource(filename).lstat();

            return runtime.newBoolean(stat != null && stat.isSymlink());
        } catch (SecurityException re) {
            return runtime.getFalse();
        } catch (RaiseException re) {
            runtime.getGlobalVariables().set("$!", oldExc);
            return runtime.getFalse();
View Full Code Here

    @JRubyMethod(name = "zero?", required = 1, module = true)
    public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) {
        Ruby runtime = context.runtime;

        FileStat stat = fileResource(context, filename).stat();

        if (stat == null) return runtime.getFalse();
        // MRI behavior, enforced by RubySpecs.
        if (stat.isDirectory()) return runtime.newBoolean(Platform.IS_WINDOWS);

        return runtime.newBoolean(stat.st_size() == 0L);
    }
View Full Code Here

    // rb_file_size but not using stat
    @JRubyMethod
    public IRubyObject size(ThreadContext context) {
        Ruby runtime = context.runtime;
        OpenFile fptr;
        FileStat st;
        long size;

        fptr = getOpenFileChecked();
        if ((fptr.getMode() & OpenFile.WRITABLE) != 0) {
            flushRaw(context, false);
View Full Code Here

                    new IRubyObject[]{runtime.newString(filename), runtime.newString("w")}, Block.NULL_BLOCK));
        }

        private void inplaceEdit(ThreadContext context, String filename, String extension) throws RaiseException {
            File file = new File(filename);
            FileStat stat = runtime.getPosix().stat(filename);

            if (!extension.equals("")) {
                file.renameTo(new File(filename + extension));
            } else {
                file.delete();
            }

            createNewFile(file);

            runtime.getPosix().chmod(filename, stat.mode());
            runtime.getPosix().chown(filename, stat.uid(), stat.gid());
            runtime.getGlobalVariables().set("$stdout", (RubyIO) RubyFile.open(context, runtime.getFile(),
                    new IRubyObject[]{runtime.newString(filename), runtime.newString("w")}, Block.NULL_BLOCK));
        }
View Full Code Here

            throw runtime.newErrnoEACCESError(path);
        }

        // Since we transcode we depend on posix to lookup stat stuff since
        // java.io.File does not seem to cut it.  A failed stat will throw ENOENT.
        FileStat stat = runtime.getPosix().stat(directory.toString());

        // is not directory
        if (!stat.isDirectory()) throw runtime.newErrnoENOTDIRError(path);

        return directory;
    }
View Full Code Here

        return file.isDirectory();
    }

    @Override
    public boolean isSymLink() {
        FileStat stat = posix.allocateStat();

        return posix.lstat(file.getAbsolutePath(), stat) < 0 ?
                false : stat.isSymlink();
    }
View Full Code Here

        return list;
    }

    @Override
    public FileStat stat() {
        FileStat stat = posix.allocateStat();

        return posix.stat(file.getAbsolutePath(), stat) < 0 ? null : stat;
    }
View Full Code Here

        return posix.stat(file.getAbsolutePath(), stat) < 0 ? null : stat;
    }

    @Override
    public FileStat lstat() {
        FileStat stat = posix.allocateStat();

        return posix.lstat(file.getAbsolutePath(), stat) < 0 ? null : stat;
    }
View Full Code Here

TOP

Related Classes of jnr.posix.FileStat

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.