org.jruby.Ruby.newErrnoEACCESError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.5k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.jruby.Ruby.newErrnoEACCESError方法的一些代码示例,展示了Ruby.newErrnoEACCESError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newErrnoEACCESError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newErrnoEACCESError

Ruby.newErrnoEACCESError介绍

暂无

代码示例

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

protected void handleSocketException(Ruby runtime, String caller, SocketException e) {
  String msg = formatMessage(e, "bind");
  // This is ugly, but what can we do, Java provides the same exception type
  // for different situations, so we differentiate the errors
  // based on the exception's message.
  if (ALREADY_BOUND_PATTERN.matcher(msg).find()) {
    throw runtime.newErrnoEINVALError(msg);
  } else if (ADDR_NOT_AVAIL_PATTERN.matcher(msg).find()) {
    throw runtime.newErrnoEADDRNOTAVAILError(msg);
  } else if (PERM_DENIED_PATTERN.matcher(msg).find()) {
    throw runtime.newErrnoEACCESError(msg);
  } else {
    throw runtime.newErrnoEADDRINUSEError(msg);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

protected void handleSocketException(Ruby runtime, String caller, SocketException e) {
  String msg = formatMessage(e, "bind");
  // This is ugly, but what can we do, Java provides the same exception type
  // for different situations, so we differentiate the errors
  // based on the exception's message.
  if (ALREADY_BOUND_PATTERN.matcher(msg).find()) {
    throw runtime.newErrnoEINVALError(msg);
  } else if (ADDR_NOT_AVAIL_PATTERN.matcher(msg).find()) {
    throw runtime.newErrnoEADDRNOTAVAILError(msg);
  } else if (PERM_DENIED_PATTERN.matcher(msg).find()) {
    throw runtime.newErrnoEACCESError(msg);
  } else {
    throw runtime.newErrnoEADDRINUSEError(msg);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

static void handleSocketException(final Ruby runtime, final SocketException ex,
  final String caller, final SocketAddress addr) {
  final String message = ex.getMessage();
  if ( message != null ) {
    switch ( message ) {
      case "permission denied" :
      case "Permission denied" :
        if ( addr == null ) {
          throw runtime.newErrnoEACCESError(caller + " - " + message);
        }
        throw runtime.newErrnoEACCESError("Address already in use - " + caller + " for " + formatAddress(addr));
      case "Address already in use" :
        throw runtime.newErrnoEADDRINUSEError(caller + " for " + formatAddress(addr));
      case "Protocol family unavailable" :
        throw runtime.newErrnoEADDRNOTAVAILError(caller + " for " + formatAddress(addr));
    }
    // This is ugly, but what can we do, Java provides the same exception type
    // for different situations, so we differentiate the errors
    // based on the exception's message.
    if (ALREADY_BOUND_PATTERN.matcher(message).find()) {
      throw runtime.newErrnoEINVALError(caller + " - " + message);
    }
    if (ADDR_NOT_AVAIL_PATTERN.matcher(message).find()) {
      throw runtime.newErrnoEADDRNOTAVAILError(caller + " - " + message);
    }
  }
  throw runtime.newErrnoEADDRINUSEError(caller + " - " + message);
}

代码示例来源:origin: org.jruby/jruby-complete

private static IRubyObject mkdirCommon(Ruby runtime, String path, IRubyObject[] args) {
  if (path.startsWith("uri:")) throw runtime.newErrnoEACCESError(path);
  path = dirFromPath(path, runtime);
  FileResource res = JRubyFile.createResource(runtime, path);
  if (res.isDirectory()) throw runtime.newErrnoEEXISTError(path);
  String name = path.replace('\\', '/');
  boolean startsWithDriveLetterOnWindows = RubyFile.startsWithDriveLetterOnWindows(name);
  // don't attempt to create a dir for drive letters
  if (startsWithDriveLetterOnWindows) {
    // path is just drive letter plus :
    if (path.length() == 2) return RubyFixnum.zero(runtime);
    // path is drive letter plus : plus leading or trailing /
    if (path.length() == 3 && (path.charAt(0) == '/' || path.charAt(2) == '/')) return RubyFixnum.zero(runtime);
    // path is drive letter plus : plus leading and trailing /
    if (path.length() == 4 && (path.charAt(0) == '/' && path.charAt(3) == '/')) return RubyFixnum.zero(runtime);
  }
  File newDir = res.unwrap(File.class);
  if (File.separatorChar == '\\') newDir = new File(newDir.getPath());
  int mode = args.length == 2 ? ((int) args[1].convertToInteger().getLongValue()) : 0777;
  if (runtime.getPosix().mkdir(newDir.getAbsolutePath(), mode) < 0) {
    // FIXME: This is a system error based on errno
    throw runtime.newSystemCallError("mkdir failed");
  }
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-complete

public static void failIfDirectory(Ruby runtime, RubyString pathStr) {
  if (RubyFileTest.directory_p(runtime, pathStr).isTrue()) {
    if (Platform.IS_WINDOWS) {
      throw runtime.newErrnoEACCESError(pathStr.asJavaString());
    } else {
      throw runtime.newErrnoEISDirError(pathStr.asJavaString());
    }
  }
}

代码示例来源:origin: org.jruby/jruby-core

public static void failIfDirectory(Ruby runtime, RubyString pathStr) {
  if (RubyFileTest.directory_p(runtime, pathStr).isTrue()) {
    if (Platform.IS_WINDOWS) {
      throw runtime.newErrnoEACCESError(pathStr.asJavaString());
    } else {
      throw runtime.newErrnoEISDirError(pathStr.asJavaString());
    }
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static void failIfDirectory(Ruby runtime, RubyString pathStr) {
  if (RubyFileTest.directory_p(runtime, pathStr).isTrue()) {
    if (Platform.IS_WINDOWS) {
      throw runtime.newErrnoEACCESError(pathStr.asJavaString());
    } else {
      throw runtime.newErrnoEISDirError(pathStr.asJavaString());
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static void failIfDirectory(Ruby runtime, RubyString pathStr) {
  if (RubyFileTest.directory_p(runtime, pathStr).isTrue()) {
    if (Platform.IS_WINDOWS) {
      throw runtime.newErrnoEACCESError(pathStr.asJavaString());
    } else {
      throw runtime.newErrnoEISDirError(pathStr.asJavaString());
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

private static String[] getEntries(ThreadContext context, FileResource dir, String path) {
  if (!dir.isDirectory()) {
    if (dir.exists()) {
      throw context.runtime.newErrnoENOTDIRError(path);
    }
    throw context.runtime.newErrnoENOENTError(path);
  }
  if (!dir.canRead()) throw context.runtime.newErrnoEACCESError(path);
  String[] list = dir.list();
  return list == null ? NO_FILES : list;
}

代码示例来源:origin: org.jruby/jruby-core

private static String[] getEntries(ThreadContext context, FileResource dir, String path) {
  if (!dir.isDirectory()) {
    if (dir.exists()) {
      throw context.runtime.newErrnoENOTDIRError(path);
    }
    throw context.runtime.newErrnoENOENTError(path);
  }
  if (!dir.canRead()) throw context.runtime.newErrnoEACCESError(path);
  String[] list = dir.list();
  return list == null ? NO_FILES : list;
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Similar to getDir, but performs different checks to match rmdir behavior.
 * @param runtime
 * @param path
 * @return
 */
protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) {
  String dir = dirFromPath(path, runtime);
  JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir);
  // Order is important here...File.exists() will return false if the parent
  // dir can't be read, so we check permissions first
  // no permission
  File parentFile = directory.getParentFile();
  if (parentFile.exists() && ! parentFile.canWrite()) {
    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;
}

代码示例来源:origin: org.jruby/jruby-core

/**
 * Similar to getDir, but performs different checks to match rmdir behavior.
 * @param runtime
 * @param path
 * @return
 */
protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) {
  String dir = dirFromPath(path, runtime);
  JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir);
  // Order is important here...File.exists() will return false if the parent
  // dir can't be read, so we check permissions first
  // no permission
  File parentFile = directory.getParentFile();
  if (parentFile.exists() && ! parentFile.canWrite()) {
    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;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Similar to getDir, but performs different checks to match rmdir behavior.
 * @param runtime
 * @param path
 * @param mustExist
 * @return
 */
protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) {
  String dir = dirFromPath(path, runtime);
  JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir);
  // Order is important here...File.exists() will return false if the parent
  // dir can't be read, so we check permissions first
  // no permission
  if (directory.getParentFile().exists() &&
      !directory.getParentFile().canWrite()) {
    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;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Similar to getDir, but performs different checks to match rmdir behavior.
 * @param runtime
 * @param path
 * @param mustExist
 * @return
 */
protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path) {
  String dir = dirFromPath(path, runtime);
  JRubyFile directory = JRubyFile.create(runtime.getCurrentDirectory(), dir);
  // Order is important here...File.exists() will return false if the parent
  // dir can't be read, so we check permissions first
  // no permission
  if (directory.getParentFile().exists() &&
      !directory.getParentFile().canWrite()) {
    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;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@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();
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@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();
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = {"unlink", "delete"}, rest = true, meta = true)
public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
  Ruby runtime = context.runtime;
     for (int i = 0; i < args.length; i++) {
    RubyString filename = get_path(context, args[i]);
    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);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(name = {"unlink", "delete"}, rest = true, meta = true)
public static IRubyObject unlink(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
  Ruby runtime = context.runtime;
     for (int i = 0; i < args.length; i++) {
    RubyString filename = get_path(context, args[i]);
    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);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(rest = true, meta = true)
public static IRubyObject delete(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
  Ruby runtime = context.runtime;
  for (int i = 0; i < args.length; i++) {
    RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i]));
    JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue());
    // Broken symlinks considered by exists() as non-existing,
    // so we need to check for symlinks explicitly.
    if (!file.exists() && !isSymlink(context, file)) {
      throw runtime.newErrnoENOENTError(filename.getUnicodeValue());
    }
    if (file.isDirectory() && !isSymlink(context, file)) {
      throw runtime.newErrnoEISDirError(filename.getUnicodeValue());
    }
    if (!file.delete()) {
      throw runtime.newErrnoEACCESError(filename.getUnicodeValue());
    }
  }
  return runtime.newFixnum(args.length);
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(rest = true, meta = true)
public static IRubyObject delete(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
  Ruby runtime = context.runtime;
  for (int i = 0; i < args.length; i++) {
    RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i]));
    JRubyFile file = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue());
    // Broken symlinks considered by exists() as non-existing,
    // so we need to check for symlinks explicitly.
    if (!file.exists() && !isSymlink(context, file)) {
      throw runtime.newErrnoENOENTError(filename.getUnicodeValue());
    }
    if (file.isDirectory() && !isSymlink(context, file)) {
      throw runtime.newErrnoEISDirError(filename.getUnicodeValue());
    }
    if (!file.delete()) {
      throw runtime.newErrnoEACCESError(filename.getUnicodeValue());
    }
  }
  return runtime.newFixnum(args.length);
}

相关文章

微信公众号

最新文章

更多

Ruby类方法