if (!initialized) return;
debug("setWorkingDirecty:enter with new working dir " + dir);
Path abs_path = makeAbsolute(dir);
-
- // error conditions if path's not a directory
- boolean isDir = false;
- boolean path_exists = false;
- try {
- isDir = isDirectory(abs_path);
- if (!isDir) path_exists = exists(abs_path);
- }
-
- catch (IOException e) {
- debug("Warning: isDirectory threw an exception");
- }
-
- if (!isDir) {
- if (path_exists)
- debug("Warning: SetWorkingDirectory(" + dir.toString() +
- "): path is not a directory");
- else
- debug("Warning: SetWorkingDirectory(" + dir.toString() +
- "): path does not exist");
- }
- else {
- debug("calling ceph_setcwd from Java");
- ceph_setcwd(abs_path.toString());
- debug("returned from ceph_setcwd to Java" );
- }
+ debug("calling ceph_setcwd from Java");
+ if (!ceph_setcwd(abs_path.toString()))
+ debug("Warning:ceph_setcwd failed for some reason on path " + abs_path);
+ debug("returned from ceph_setcwd to Java" );
debug("setWorkingDirectory:exit");
}
+"CephFileSystem before calling other methods.");
debug("listStatus:enter with path " + path);
Path abs_path = makeAbsolute(path);
- if (isDirectory(abs_path)) {
- Path[] paths = listPaths(abs_path);
+ Path[] paths = listPaths(abs_path);
+ if (paths != null) {
FileStatus[] statuses = new FileStatus[paths.length];
for (int i = 0; i < paths.length; ++i) {
statuses[i] = getFileStatus(paths[i]);
debug("listStatus:exit");
return statuses;
}
- return null; //it's a file, or DNE
+ if (!isFile(path)) throw new FileNotFoundException(); //if we get here, listPaths returned null
+ //which means that the input wasn't a directory, so throw an Exception if it's not a file
+ return null; //or return null if it's a file
}
@Override
// throw an exception if !CreateFlag.OVERWRITE.
// Step 1: existence test
- if(isDirectory(abs_path))
- throw new IOException("create: Cannot overwrite existing directory \""
- + path.toString() + "\" with a file");
- if (progress!=null) progress.progress();
- // if (!flag.contains(CreateFlag.OVERWRITE)) {
- if (!overwrite) {
- if (exists(abs_path)) {
+ boolean exists = exists(abs_path);
+ if (exists) {
+ if(isDirectory(abs_path))
+ throw new IOException("create: Cannot overwrite existing directory \""
+ + path.toString() + "\" with a file");
+ if (!overwrite)
+ //if (!flag.contains(CreateFlag.OVERWRITE)) {
throw new IOException("createRaw: Cannot open existing file \""
+ abs_path.toString()
+ "\" for writing without overwrite flag");
- }
}
+ if (progress!=null) progress.progress();
+
// Step 2: create any nonexistent directories in the path
- Path parent = abs_path.getParent();
- if (parent != null) { // if parent is root, we're done
- int r = ceph_mkdirs(parent.toString(), permission.toShort());
- if (!(r==0 || r==-EEXIST))
- throw new IOException ("Error creating parent directory; code: " + r);
+ if (!exists) {
+ Path parent = abs_path.getParent();
+ if (parent != null) { // if parent is root, we're done
+ int r = ceph_mkdirs(parent.toString(), permission.toShort());
+ if (!(r==0 || r==-EEXIST))
+ throw new IOException ("Error creating parent directory; code: " + r);
+ }
+ if (progress!=null) progress.progress();
}
- if (progress!=null) progress.progress();
// Step 3: open the file
debug("calling ceph_open_for_overwrite from Java");
int fh = ceph_open_for_overwrite(abs_path.toString(), (int)permission.toShort());
debug("open:enter with path " + path);
Path abs_path = makeAbsolute(path);
- if(!isFile(abs_path)) {
- if (!exists(abs_path))
- throw new IOException("open: absolute path \"" + abs_path.toString()
- + "\" does not exist");
- else
- throw new IOException("open: absolute path \"" + abs_path.toString()
- + "\" is not a file");
- }
-
+ if (!exists(abs_path))
+ throw new IOException("open: absolute path \"" + abs_path.toString()
+ + "\" does not exist");
+ if(!isFile(abs_path))
+ throw new IOException("open: absolute path \"" + abs_path.toString()
+ + "\" is not a file");
+
int fh = ceph_open_for_read(abs_path.toString());
if (fh < 0) {
throw new IOException("open: Failed to open file " + abs_path.toString());
FSInputStream cephIStream = new CephInputStream(getConf(), fh, size);
debug("open:exit");
return new FSDataInputStream(cephIStream);
- }
+ }
/**
* Rename a file or directory.
// sanity check
if (abs_path.toString().equals(root))
throw new IOException("Error: deleting the root directory is a Bad Idea.");
-
+
+ if (!exists(abs_path)) return false;
+
// if the path is a file, try to delete it.
if (isFile(abs_path)) {
boolean result = ceph_unlink(abs_path.toString());
return result;
}
- if (!isDirectory(abs_path)) return false;
-
- /* If the path is a directory, recursively try to delete its contents,
+ /* The path is a directory, so recursively try to delete its contents,
and then delete the directory. */
if (!recursive) {
throw new IOException("Directories must be deleted recursively!");
+"CephFileSystem before calling other methods.");
debug("getBlockSize:enter with path " + path);
Path abs_path = makeAbsolute(path);
- if (!exists(abs_path)) {
- throw new IOException("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: File or directory " + path.toString() + " does not exist.");
- }
long result = ceph_getblocksize(abs_path.toString());
-
- if (result < 4096) {
- debug("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: " +
- "path exists; strange block size of " + result + " defaulting to 4096");
- return 4096;
- }
+
+ if (result < 0)
+ throw new IOException("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: File or directory "
+ + path.toString() + " does not exist.");
+
debug("getBlockSize:exit with result " + result);
return result;
}
Path abs_path = makeAbsolute(path);
// If it's a directory, get the listing. Otherwise, complain and give up.
- if (isDirectory(abs_path)) {
- debug("calling ceph_getdir from Java with path " + abs_path);
- dirlist = ceph_getdir(abs_path.toString());
- debug("returning from ceph_getdir to Java");
- }
- else {
+ debug("calling ceph_getdir from Java with path " + abs_path);
+ dirlist = ceph_getdir(abs_path.toString());
+ debug("returning from ceph_getdir to Java");
+
+ if (dirlist == null) {
throw new IOException("listPaths: path " + path.toString() + " is not a directory.");
}