use of org.javaswift.joss.model.DirectoryOrObject in project stocator by CODAIT.
the class SwiftAPIClient method getFileStatus.
@Override
public FileStatus getFileStatus(String hostName, Path path, String msg) throws IOException, FileNotFoundException {
LOG.trace("Get object metadata ({}): {}, hostname: {}", msg, path, hostName);
Container cont = mJossAccount.getAccount().getContainer(container);
/*
* Check if the path is a temporary URL
*/
if (path.toString().contains("temp_url")) {
long length = SwiftAPIDirect.getTempUrlObjectLength(path, swiftConnectionManager);
return new FileStatus(length, false, 1, blockSize, 0L, path);
}
/*
The requested path is equal to hostName.
HostName is equal to hostNameScheme, thus the container.
Therefore we have no object to look for and
we return the FileStatus as a directory.
Containers have to lastModified.
*/
if (path.toString().equals(hostName) || (path.toString().length() + 1 == hostName.length())) {
LOG.debug("{}: metadata requested on container", path.toString());
return new FileStatus(0L, true, 1, blockSize, 0L, path);
}
/*
The requested path is not equal to the container.
We need to check if the object requested is a real object or a directory.
This may be triggered when users want to access a directory rather than
the entire container.
A directory in Swift can have two implementations:
1) a zero byte object with the name of the directory
2) no zero byte object with the name of the directory
*/
boolean isDirectory = false;
String objectName = getObjName(hostName, path);
if (stocatorPath.isTemporaryPathContain(objectName)) {
LOG.debug("getObjectMetadata on temp object {}. Return not found", objectName);
throw new FileNotFoundException("Not found " + path.toString());
}
SwiftCachedObject obj = objectCache.get(objectName);
if (obj != null) {
// If so, it might be a directory
if (obj.getContentLength() == 0) {
Collection<DirectoryOrObject> directoryFiles = cont.listDirectory(objectName, '/', "", 10);
if (directoryFiles != null && directoryFiles.size() != 0) {
// The zero length object is a directory
isDirectory = true;
}
}
LOG.trace("{} is object. isDirectory: {} lastModified: {}", path.toString(), isDirectory, obj.getLastModified());
return new FileStatus(obj.getContentLength(), isDirectory, 1, blockSize, obj.getLastModified(), path);
}
// We need to check if it may be a directory with no zero byte file associated
LOG.trace("Checking if directory without 0 byte object associated {}", objectName);
Collection<DirectoryOrObject> directoryFiles = cont.listDirectory(objectName + "/", '/', "", 10);
if (directoryFiles != null) {
LOG.trace("{} got {} candidates", objectName + "/", directoryFiles.size());
}
if (directoryFiles != null && directoryFiles.size() != 0) {
// In this case there is no lastModified
isDirectory = true;
LOG.debug("Got object {}. isDirectory: {} lastModified: {}", path, isDirectory, null);
return new FileStatus(0, isDirectory, 1, blockSize, 0L, path);
}
LOG.debug("Not found {}", path.toString());
throw new FileNotFoundException("No such object exists " + path.toString());
}
use of org.javaswift.joss.model.DirectoryOrObject in project stocator by SparkTC.
the class SwiftAPIClient method getFileStatus.
@Override
public FileStatus getFileStatus(String hostName, Path path, String msg) throws IOException, FileNotFoundException {
LOG.trace("Get object metadata ({}): {}, hostname: {}", msg, path, hostName);
Container cont = mJossAccount.getAccount().getContainer(container);
/*
* Check if the path is a temporary URL
*/
if (path.toString().contains("temp_url")) {
long length = SwiftAPIDirect.getTempUrlObjectLength(path, swiftConnectionManager);
return new FileStatus(length, false, 1, blockSize, 0L, path);
}
/*
The requested path is equal to hostName.
HostName is equal to hostNameScheme, thus the container.
Therefore we have no object to look for and
we return the FileStatus as a directory.
Containers have to lastModified.
*/
if (path.toString().equals(hostName) || (path.toString().length() + 1 == hostName.length())) {
LOG.debug("{}: metadata requested on container", path.toString());
return new FileStatus(0L, true, 1, blockSize, 0L, path);
}
/*
The requested path is not equal to the container.
We need to check if the object requested is a real object or a directory.
This may be triggered when users want to access a directory rather than
the entire container.
A directory in Swift can have two implementations:
1) a zero byte object with the name of the directory
2) no zero byte object with the name of the directory
*/
boolean isDirectory = false;
String objectName = getObjName(hostName, path);
if (stocatorPath.isTemporaryPathContain(objectName)) {
LOG.debug("getObjectMetadata on temp object {}. Return not found", objectName);
throw new FileNotFoundException("Not found " + path.toString());
}
SwiftCachedObject obj = objectCache.get(objectName);
if (obj != null) {
// If so, it might be a directory
if (obj.getContentLength() == 0) {
Collection<DirectoryOrObject> directoryFiles = cont.listDirectory(objectName, '/', "", 10);
if (directoryFiles != null && directoryFiles.size() != 0) {
// The zero length object is a directory
isDirectory = true;
}
}
LOG.trace("{} is object. isDirectory: {} lastModified: {}", path.toString(), isDirectory, obj.getLastModified());
return new FileStatus(obj.getContentLength(), isDirectory, 1, blockSize, obj.getLastModified(), path);
}
// We need to check if it may be a directory with no zero byte file associated
LOG.trace("Checking if directory without 0 byte object associated {}", objectName);
Collection<DirectoryOrObject> directoryFiles = cont.listDirectory(objectName + "/", '/', "", 10);
if (directoryFiles != null) {
LOG.trace("{} got {} candidates", objectName + "/", directoryFiles.size());
}
if (directoryFiles != null && directoryFiles.size() != 0) {
// In this case there is no lastModified
isDirectory = true;
LOG.debug("Got object {}. isDirectory: {} lastModified: {}", path, isDirectory, null);
return new FileStatus(0, isDirectory, 1, blockSize, 0L, path);
}
LOG.debug("Not found {}", path.toString());
throw new FileNotFoundException("No such object exists " + path.toString());
}
Aggregations