/** * Java does not give us enough information for specific error conditions * so we are reduced to divining them through string matches... * * TODO: Should ECONNABORTED get thrown earlier in the descriptor itself or is it ok to handle this late? * TODO: Should we include this into Errno code somewhere do we can use this from other places as well? */ public static RaiseException newIOErrorFromException(Ruby runtime, IOException ex) { Errno errno = errnoFromException(ex); if (errno == null) throw runtime.newIOError(ex.getLocalizedMessage()); throw runtime.newErrnoFromErrno(errno, ex.getLocalizedMessage()); }
/** * Java does not give us enough information for specific error conditions * so we are reduced to divining them through string matches... * * TODO: Should ECONNABORTED get thrown earlier in the descriptor itself or is it ok to handle this late? * TODO: Should we include this into Errno code somewhere do we can use this from other places as well? */ public static RaiseException newIOErrorFromException(Ruby runtime, IOException ex) { Errno errno = errnoFromException(ex); if (errno == null) throw runtime.newIOError(ex.getLocalizedMessage()); throw runtime.newErrnoFromErrno(errno, ex.getLocalizedMessage()); }
public static RubyFixnum spawn(ThreadContext context, IRubyObject[] argv) { Ruby runtime = context.runtime; long pid = 0; String[] errmsg = { null }; ExecArg eargp; IRubyObject fail_str; eargp = execargNew(context, argv, true); execargFixup(context, runtime, eargp); fail_str = eargp.use_shell ? eargp.command_name : eargp.command_name; PopenExecutor executor = new PopenExecutor(); pid = executor.spawnProcess(context, runtime, eargp, errmsg); if (pid == -1) { if (errmsg[0] == null) { throw runtime.newErrnoFromErrno(executor.errno, fail_str.toString()); } throw runtime.newErrnoFromErrno(executor.errno, errmsg[0]); } return runtime.newFixnum(pid); }
protected static ChannelFD sysopen(Ruby runtime, String fname, int oflags, int perm) { ChannelFD fd; Sysopen data = new Sysopen(); data.fname = fname; data.oflags = oflags; data.perm = perm; fd = sysopenInternal(runtime, data); if (fd == null) { if (data.errno != null) { throw runtime.newErrnoFromErrno(data.errno, fname); } else { throw runtime.newSystemCallError(fname); } } return fd; }
public void checkCharReadable(ThreadContext context) { checkClosed(); if ((mode & READABLE) == 0) { throw runtime.newIOError("not opened for reading"); } if (wbuf.len != 0) { if (io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(posix.errno, "error flushing"); } } if (tiedIOForWriting != null) { OpenFile wfptr; wfptr = tiedIOForWriting.getOpenFileChecked(); if (wfptr.io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(wfptr.posix.errno, wfptr.getPath()); } } }
protected static ChannelFD sysopen(Ruby runtime, String fname, int oflags, int perm) { ChannelFD fd; Sysopen data = new Sysopen(); data.fname = fname; data.oflags = oflags; data.perm = perm; fd = sysopenInternal(runtime, data); if (fd == null) { if (data.errno != null) { throw runtime.newErrnoFromErrno(data.errno, fname); } else { throw runtime.newSystemCallError(fname); } } return fd; }
public void checkCharReadable(ThreadContext context) { checkClosed(); if ((mode & READABLE) == 0) { throw runtime.newIOError("not opened for reading"); } if (wbuf.len != 0) { if (io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(posix.errno, "error flushing"); } } if (tiedIOForWriting != null) { OpenFile wfptr; wfptr = tiedIOForWriting.getOpenFileChecked(); if (wfptr.io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(wfptr.posix.errno, wfptr.getPath()); } } }
public void checkReopenSeek(ThreadContext context, Ruby runtime, long pos) { if (seek(context, pos, PosixShim.SEEK_SET) == -1 && errno() != null) { throw runtime.newErrnoFromErrno(errno(), getPath()); } }
private void flushBeforeSeek(ThreadContext context) { boolean locked = lock(); try { if (io_fflush(context) < 0) throw context.runtime.newErrnoFromErrno(posix.errno, ""); unread(context); posix.errno = null; } finally { if (locked) unlock(); } }
public void checkReopenSeek(ThreadContext context, Ruby runtime, long pos) { if (seek(context, pos, PosixShim.SEEK_SET) == -1 && errno() != null) { throw runtime.newErrnoFromErrno(errno(), getPath()); } }
private void flushBeforeSeek(ThreadContext context) { boolean locked = lock(); try { if (io_fflush(context) < 0) throw context.runtime.newErrnoFromErrno(posix.errno, ""); unread(context); posix.errno = null; } finally { if (locked) unlock(); } }
public int fread(ThreadContext context, IRubyObject str, int offset, int size) { int len; BufreadArg arg = new BufreadArg(); str = EncodingUtils.setStrBuf(context.runtime, str, offset + size); ByteList strByteList = ((RubyString)str).getByteList(); arg.strPtrBytes = strByteList.unsafeBytes(); arg.strPtr = strByteList.begin() + offset; arg.len = size; arg.fptr = this; // we don't support string locking // rb_str_locktmp_ensure(str, bufread_call, (VALUE)&arg); bufreadCall(context, arg); len = arg.len; // should be errno if (len < 0) throw context.runtime.newErrnoFromErrno(posix.errno, pathv); return len; }
public int fread(ThreadContext context, IRubyObject str, int offset, int size) { int len; BufreadArg arg = new BufreadArg(); str = EncodingUtils.setStrBuf(context.runtime, str, offset + size); ByteList strByteList = ((RubyString)str).getByteList(); arg.strPtrBytes = strByteList.unsafeBytes(); arg.strPtr = strByteList.begin() + offset; arg.len = size; arg.fptr = this; // we don't support string locking // rb_str_locktmp_ensure(str, bufread_call, (VALUE)&arg); bufreadCall(context, arg); len = arg.len; // should be errno if (len < 0) throw context.runtime.newErrnoFromErrno(posix.errno, pathv); return len; }
private long doSeek(ThreadContext context, long pos, int whence) { OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, whence); if (pos < 0 && fptr.errno() != null) { throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } } finally { if (locked) fptr.unlock(); } return 0; }
private long doSeek(ThreadContext context, long pos, int whence) { OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, whence); if (pos < 0 && fptr.errno() != null) { throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } } finally { if (locked) fptr.unlock(); } return 0; }
@JRubyMethod(name = {"pos", "tell"}) public RubyFixnum pos(ThreadContext context) { OpenFile fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { long pos = fptr.tell(context); if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); pos -= fptr.rbuf.len; return context.runtime.newFixnum(pos); } finally { if (locked) fptr.unlock(); } }
@JRubyMethod(name = {"pos", "tell"}) public RubyFixnum pos(ThreadContext context) { OpenFile fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { long pos = fptr.tell(context); if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); pos -= fptr.rbuf.len; return context.runtime.newFixnum(pos); } finally { if (locked) fptr.unlock(); } }
@JRubyMethod(name = "pos=", required = 1) public RubyFixnum pos_set(ThreadContext context, IRubyObject offset) { OpenFile fptr; long pos; pos = offset.convertToInteger().getLongValue(); fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, PosixShim.SEEK_SET); if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } finally { if (locked) fptr.unlock(); } return context.runtime.newFixnum(pos); }
@JRubyMethod(name = "pos=", required = 1) public RubyFixnum pos_set(ThreadContext context, IRubyObject offset) { OpenFile fptr; long pos; pos = offset.convertToInteger().getLongValue(); fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, PosixShim.SEEK_SET); if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } finally { if (locked) fptr.unlock(); } return context.runtime.newFixnum(pos); }
@JRubyMethod(required = 1) public IRubyObject truncate(ThreadContext context, IRubyObject len) { Ruby runtime = context.runtime; OpenFile fptr; long pos; pos = RubyNumeric.num2int(len); fptr = getOpenFileChecked(); if (!fptr.isWritable()) { throw runtime.newIOError("not opened for writing"); } flushRaw(context, false); if (pos < 0) { throw runtime.newErrnoEINVALError(openFile.getPath()); } if (fptr.posix.ftruncate(fptr.fd(), pos) < 0) { throw runtime.newErrnoFromErrno(fptr.posix.errno, fptr.getPath()); } return RubyFixnum.zero(runtime); }