private long sizeInternal() { // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
private long sizeInternal() { // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
private long sizeInternal() { checkInitialized(); // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
private long sizeInternal() { checkInitialized(); // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
@JRubyMethod(name = "size", required = 1, module = true) public static IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject filename) { if (!(filename instanceof RubyFile) && filename.respondsTo("to_io")) { filename = TypeConverter.convertToType(filename, context.runtime.getIO(), "to_io"); } FileStat stat = fileResource(filename).stat(); if (stat == null) noFileError(filename); return context.runtime.newFixnum(stat.st_size()); }
@JRubyMethod(name = "size", required = 1, module = true) public static IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject filename) { if (!(filename instanceof RubyFile) && filename.respondsTo("to_io")) { filename = TypeConverter.convertToType(filename, context.runtime.getIO(), "to_io"); } FileStat stat = fileResource(filename).stat(); if (stat == null) noFileError(filename); return context.runtime.newFixnum(stat.st_size()); }
@JRubyMethod(name = "size?", required = 1, module = true) public static IRubyObject size_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile) && filename.respondsTo("to_io")) { filename = TypeConverter.convertToType(filename, runtime.getIO(), "to_io"); } FileStat stat = fileResource(filename).stat(); if (stat == null) return runtime.getNil(); long length = stat.st_size(); return length > 0 ? runtime.newFixnum(length) : runtime.getNil(); }
@JRubyMethod(name = {"empty?", "zero?"}, required = 1, module = true) public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; FileResource resource = fileResource(context, filename); // FIXME: Ultimately we should return a valid stat() from this but without massive NUL coverage // this is less risky. if (resource.isNull()) return runtime.newBoolean(true); FileStat stat = resource.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); }
@JRubyMethod(name = "size?", required = 1, module = true) public static IRubyObject size_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile) && filename.respondsTo("to_io")) { filename = TypeConverter.convertToType(filename, runtime.getIO(), "to_io"); } FileStat stat = fileResource(filename).stat(); if (stat == null) return runtime.getNil(); long length = stat.st_size(); return length > 0 ? runtime.newFixnum(length) : runtime.getNil(); }
public long size(ChannelFD fd) { if (fd.chNative != null) { // native fd, use fstat FileStat stat = posix.allocateStat(); int ret = posix.fstat(fd.chNative.getFD(), stat); if (ret == -1) { errno = Errno.valueOf(posix.errno()); return -1; } return stat.st_size(); } else if (fd.chSeek != null) { // if it is seekable, get size directly try { return fd.chSeek.size(); } catch (IOException ioe) { errno = Helpers.errnoFromException(ioe); return -1; } } else { // otherwise just return -1 (should be rare, since size is only defined on File errno = Errno.EINVAL; return -1; } }
public long size(ChannelFD fd) { if (fd.chNative != null) { // native fd, use fstat FileStat stat = posix.allocateStat(); int ret = posix.fstat(fd.chNative.getFD(), stat); if (ret == -1) { errno = Errno.valueOf(posix.errno()); return -1; } return stat.st_size(); } else if (fd.chSeek != null) { // if it is seekable, get size directly try { return fd.chSeek.size(); } catch (IOException ioe) { errno = Helpers.errnoFromException(ioe); return -1; } } else { // otherwise just return -1 (should be rare, since size is only defined on File errno = Errno.EINVAL; return -1; } }
@JRubyMethod(name = {"empty?", "zero?"}, required = 1, module = true) public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; FileResource resource = fileResource(context, filename); // FIXME: Ultimately we should return a valid stat() from this but without massive NUL coverage // this is less risky. if (resource.isNull()) return runtime.newBoolean(true); FileStat stat = resource.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); }
@JRubyMethod(name = "size", compat = RUBY1_9) public IRubyObject size(ThreadContext context) { Ruby runtime = context.runtime; if ((openFile.getMode() & OpenFile.WRITABLE) != 0) flush(); // FIXME: jnr-posix is calling _osf_close + throwing random native exceptions with weird paths. // Once these are fixed remove this full file stat path and go back to faster one. if (Platform.IS_WINDOWS) return runtime.newFileStat(path, false).size(); try { FileDescriptor fd = getOpenFileChecked().getMainStreamSafe().getDescriptor().getFileDescriptor(); FileStat stat = runtime.getPosix().fstat(fd); if (stat == null) throw runtime.newErrnoEACCESError(path); return runtime.newFixnum(stat.st_size()); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }
@JRubyMethod(name = "size", compat = RUBY1_9) public IRubyObject size(ThreadContext context) { Ruby runtime = context.runtime; if ((openFile.getMode() & OpenFile.WRITABLE) != 0) flush(); // FIXME: jnr-posix is calling _osf_close + throwing random native exceptions with weird paths. // Once these are fixed remove this full file stat path and go back to faster one. if (Platform.IS_WINDOWS) return runtime.newFileStat(path, false).size(); try { FileDescriptor fd = getOpenFileChecked().getMainStreamSafe().getDescriptor().getFileDescriptor(); FileStat stat = runtime.getPosix().fstat(fd); if (stat == null) throw runtime.newErrnoEACCESError(path); return runtime.newFixnum(stat.st_size()); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }
public static PyStatResult fromFileStat(FileStat stat) { return new PyStatResult( Py.newInteger(stat.mode()), Py.newInteger(stat.ino()), Py.newLong(stat.dev()), Py.newInteger(stat.nlink()), Py.newInteger(stat.uid()), Py.newInteger(stat.gid()), Py.newInteger(stat.st_size()), Py.newFloat(stat.atime()), Py.newFloat(stat.mtime()), Py.newFloat(stat.ctime())); }