File parent = f.getParentFile(); File dir = null; while (parent != null && FileUtil.canWrite(parent) && parent.toString().startsWith(device)) { dir = parent;
/** * Checks that the current running process can read, write, and execute the * given directory by using methods of the File object. * * @param dir File to check * @throws DiskErrorException if dir is not readable, not writable, or not * executable */ private static void checkAccessByFileMethods(File dir) throws DiskErrorException { if (!dir.isDirectory()) { throw new DiskErrorException("Not a directory: " + dir.toString()); } if (!FileUtil.canRead(dir)) { throw new DiskErrorException("Directory is not readable: " + dir.toString()); } if (!FileUtil.canWrite(dir)) { throw new DiskErrorException("Directory is not writable: " + dir.toString()); } if (!FileUtil.canExecute(dir)) { throw new DiskErrorException("Directory is not executable: " + dir.toString()); } }
/** * See if any of removed storages is "writable" again, and can be returned * into service. */ void attemptRestoreRemovedStorage() { // if directory is "alive" - copy the images there... if(!restoreFailedStorage || removedStorageDirs.size() == 0) { return; //nothing to restore } /* We don't want more than one thread trying to restore at a time */ synchronized (this.restorationLock) { LOG.info("NNStorage.attemptRestoreRemovedStorage: check removed(failed) "+ "storage. removedStorages size = {}", removedStorageDirs.size()); for (StorageDirectory sd : this.removedStorageDirs) { File root = sd.getRoot(); LOG.info("currently disabled dir {}; type={} ;canwrite={}", root .getAbsolutePath(), sd.getStorageDirType(), FileUtil.canWrite(root)); if (root.exists() && FileUtil.canWrite(root)) { LOG.info("restoring dir {}", sd.getRoot().getAbsolutePath()); this.addStorageDir(sd); // restore this.removedStorageDirs.remove(sd); } } } }
if (FileUtil.canWrite(destFile) == false) { throw new IOException("Destination '" + destFile + "' exists but is read-only");
return StorageState.NON_EXISTENT; if (!FileUtil.canWrite(root)) { LOG.warn("Cannot access storage directory {}", rootPath); return StorageState.NON_EXISTENT;
private void initializeControllerPaths() throws IOException { String controllerPath; Map<String, List<String>> parsedMtab = parseMtab(); // CPU controllerPath = findControllerInMtab(CONTROLLER_CPU, parsedMtab); if (controllerPath != null) { File f = new File(controllerPath + "/" + this.cgroupPrefix); if (FileUtil.canWrite(f)) { controllerPaths.put(CONTROLLER_CPU, controllerPath); } else { throw new IOException("Not able to enforce cpu weights; cannot write " + "to cgroup at: " + controllerPath); } } else { throw new IOException("Not able to enforce cpu weights; cannot find " + "cgroup for cpu controller in " + getMtabFileName()); } }
private void initializeControllerPaths() throws IOException { String controllerPath; Map<String, List<String>> parsedMtab = parseMtab(); // CPU controllerPath = findControllerInMtab(CONTROLLER_CPU, parsedMtab); if (controllerPath != null) { File f = new File(controllerPath + "/" + this.cgroupPrefix); if (FileUtil.canWrite(f)) { controllerPaths.put(CONTROLLER_CPU, controllerPath); } else { throw new IOException("Not able to enforce cpu weights; cannot write " + "to cgroup at: " + controllerPath); } } else { throw new IOException("Not able to enforce cpu weights; cannot find " + "cgroup for cpu controller in " + getMtabFileName()); } }
/** * See if any of removed storages is "writable" again, and can be returned * into service. */ void attemptRestoreRemovedStorage() { // if directory is "alive" - copy the images there... if(!restoreFailedStorage || removedStorageDirs.size() == 0) return; //nothing to restore /* We don't want more than one thread trying to restore at a time */ synchronized (this.restorationLock) { LOG.info("NNStorage.attemptRestoreRemovedStorage: check removed(failed) "+ "storarge. removedStorages size = " + removedStorageDirs.size()); for(Iterator<StorageDirectory> it = this.removedStorageDirs.iterator(); it.hasNext();) { StorageDirectory sd = it.next(); File root = sd.getRoot(); LOG.info("currently disabled dir " + root.getAbsolutePath() + "; type="+sd.getStorageDirType() + ";canwrite="+FileUtil.canWrite(root)); if(root.exists() && FileUtil.canWrite(root)) { LOG.info("restoring dir " + sd.getRoot().getAbsolutePath()); this.addStorageDir(sd); // restore this.removedStorageDirs.remove(sd); } } } }
private void initializeControllerPaths() throws IOException { String controllerPath; Map<String, List<String>> parsedMtab = parseMtab(); // CPU controllerPath = findControllerInMtab(CONTROLLER_CPU, parsedMtab); if (controllerPath != null) { File f = new File(controllerPath + "/" + this.cgroupPrefix); if (FileUtil.canWrite(f)) { controllerPaths.put(CONTROLLER_CPU, controllerPath); } else { throw new IOException("Not able to enforce cpu weights; cannot write " + "to cgroup at: " + controllerPath); } } else { throw new IOException("Not able to enforce cpu weights; cannot find " + "cgroup for cpu controller in " + getMtabFileName()); } }
File parent = f.getParentFile(); File dir = null; while (parent != null && FileUtil.canWrite(parent) && parent.toString().startsWith(device)) { dir = parent;
File parent = f.getParentFile(); File dir = null; while (parent != null && FileUtil.canWrite(parent) && parent.toString().startsWith(device)) { dir = parent;
File f = new File(controllerPath + "/" + cGroupPrefix); if (FileUtil.canWrite(f)) { ret.put(controller, controllerPath); } else {
/** * See if any of removed storages is "writable" again, and can be returned * into service. */ void attemptRestoreRemovedStorage() { // if directory is "alive" - copy the images there... if(!restoreFailedStorage || removedStorageDirs.size() == 0) return; //nothing to restore /* We don't want more than one thread trying to restore at a time */ synchronized (this.restorationLock) { LOG.info("NNStorage.attemptRestoreRemovedStorage: check removed(failed) "+ "storarge. removedStorages size = " + removedStorageDirs.size()); for(Iterator<StorageDirectory> it = this.removedStorageDirs.iterator(); it.hasNext();) { StorageDirectory sd = it.next(); File root = sd.getRoot(); LOG.info("currently disabled dir " + root.getAbsolutePath() + "; type="+sd.getStorageDirType() + ";canwrite="+FileUtil.canWrite(root)); if(root.exists() && FileUtil.canWrite(root)) { LOG.info("restoring dir " + sd.getRoot().getAbsolutePath()); this.addStorageDir(sd); // restore this.removedStorageDirs.remove(sd); } } } }
private void initializeControllerPaths() throws IOException { String controllerPath; Map<String, Set<String>> parsedMtab = null; if (this.cgroupMountPath != null && !this.cgroupMount) { parsedMtab = ResourceHandlerModule. parseConfiguredCGroupPath(this.cgroupMountPath); } if (parsedMtab == null) { parsedMtab = parseMtab(); } // CPU controllerPath = findControllerInMtab(CONTROLLER_CPU, parsedMtab); if (controllerPath != null) { File f = new File(controllerPath + "/" + this.cgroupPrefix); if (FileUtil.canWrite(f)) { controllerPaths.put(CONTROLLER_CPU, controllerPath); } else { throw new IOException("Not able to enforce cpu weights; cannot write " + "to cgroup at: " + controllerPath); } } else { throw new IOException("Not able to enforce cpu weights; cannot find " + "cgroup for cpu controller in " + getMtabFileName()); } }
/** * Checks that the current running process can read, write, and execute the * given directory by using methods of the File object. * * @param dir File to check * @throws DiskErrorException if dir is not readable, not writable, or not * executable */ private static void checkAccessByFileMethods(File dir) throws DiskErrorException { if (!dir.isDirectory()) { throw new DiskErrorException("Not a directory: " + dir.toString()); } if (!FileUtil.canRead(dir)) { throw new DiskErrorException("Directory is not readable: " + dir.toString()); } if (!FileUtil.canWrite(dir)) { throw new DiskErrorException("Directory is not writable: " + dir.toString()); } if (!FileUtil.canExecute(dir)) { throw new DiskErrorException("Directory is not executable: " + dir.toString()); } }
/** * Checks that the current running process can read, write, and execute the * given directory by using methods of the File object. * * @param dir File to check * @throws DiskErrorException if dir is not readable, not writable, or not * executable */ private static void checkAccessByFileMethods(File dir) throws DiskErrorException { if (!FileUtil.canRead(dir)) { throw new DiskErrorException("Directory is not readable: " + dir.toString()); } if (!FileUtil.canWrite(dir)) { throw new DiskErrorException("Directory is not writable: " + dir.toString()); } if (!FileUtil.canExecute(dir)) { throw new DiskErrorException("Directory is not executable: " + dir.toString()); } } }
/** * Checks that the current running process can read, write, and execute the * given directory by using methods of the File object. * * @param dir File to check * @throws DiskErrorException if dir is not readable, not writable, or not * executable */ private static void checkAccessByFileMethods(File dir) throws DiskErrorException { if (!FileUtil.canRead(dir)) { throw new DiskErrorException("Directory is not readable: " + dir.toString()); } if (!FileUtil.canWrite(dir)) { throw new DiskErrorException("Directory is not writable: " + dir.toString()); } if (!FileUtil.canExecute(dir)) { throw new DiskErrorException("Directory is not executable: " + dir.toString()); } } }
/** * Checks that the current running process can read, write, and execute the * given directory by using methods of the File object. * * @param dir File to check * @throws DiskErrorException if dir is not readable, not writable, or not * executable */ private static void checkAccessByFileMethods(File dir) throws DiskErrorException { if (!FileUtil.canRead(dir)) { throw new DiskErrorException("Directory is not readable: " + dir.toString()); } if (!FileUtil.canWrite(dir)) { throw new DiskErrorException("Directory is not writable: " + dir.toString()); } if (!FileUtil.canExecute(dir)) { throw new DiskErrorException("Directory is not executable: " + dir.toString()); } } }
/** * @return a debug string which can help diagnose an error of why * a given directory might have a permissions error in the context * of a test case */ private String createPermissionsDiagnosisString(File path) { StringBuilder sb = new StringBuilder(); while (path != null) { sb.append("path '" + path + "': ").append("\n"); sb.append("\tabsolute:").append(path.getAbsolutePath()).append("\n"); sb.append("\tpermissions: "); sb.append(path.isDirectory() ? "d": "-"); sb.append(FileUtil.canRead(path) ? "r" : "-"); sb.append(FileUtil.canWrite(path) ? "w" : "-"); sb.append(FileUtil.canExecute(path) ? "x" : "-"); sb.append("\n"); path = path.getParentFile(); } return sb.toString(); }