use of org.apache.commons.vfs2.FileType in project jackrabbit by apache.
the class VFSTestUtils method deleteAllDescendantFiles.
/**
* Deletes all the descendant files under the folder.
* @param folderObject folder object
* @throws FileSystemException if any file system exception occurs
* @throws DataStoreException if any file system exception occurs
*/
static void deleteAllDescendantFiles(FileObject folderObject) throws FileSystemException, DataStoreException {
List<FileObject> children = VFSUtils.getChildFileOrFolders(folderObject);
FileType fileType;
for (FileObject child : children) {
fileType = child.getType();
if (fileType == FileType.FILE) {
boolean deleted = child.delete();
if (!deleted) {
LOG.warn("File not deleted: {}", child.getName().getFriendlyURI());
}
} else if (fileType == FileType.FOLDER) {
deleteAllDescendantFiles(child);
}
}
}
use of org.apache.commons.vfs2.FileType in project jackrabbit by apache.
the class VFSBackend method deleteOlderRecursive.
/**
* Deletes any descendant record files under {@code folderObject} if the record files are older than {@code timestamp},
* and push all the deleted record identifiers into {@code deleteIdSet}.
* @param deleteIdSet set to store all the deleted record identifiers
* @param folderObject folder object to start with
* @param timestamp timestamp
* @throws FileSystemException if any file system exception occurs
* @throws DataStoreException if any file system exception occurs
*/
private void deleteOlderRecursive(Set<DataIdentifier> deleteIdSet, FileObject folderObject, long timestamp) throws FileSystemException, DataStoreException {
FileType type;
DataIdentifier identifier;
for (FileObject fileObject : VFSUtils.getChildFileOrFolders(folderObject)) {
type = fileObject.getType();
if (type == FileType.FOLDER) {
deleteOlderRecursive(deleteIdSet, fileObject, timestamp);
synchronized (this) {
if (!VFSUtils.hasAnyChildFileOrFolder(fileObject)) {
fileObject.delete();
}
}
} else if (type == FileType.FILE) {
long lastModified = getLastModifiedTime(fileObject);
if (lastModified < timestamp) {
identifier = new DataIdentifier(fileObject.getName().getBaseName());
if (getDataStore().confirmDelete(identifier)) {
getDataStore().deleteFromCache(identifier);
if (LOG.isInfoEnabled()) {
LOG.info("Deleting old file " + fileObject.getName().getFriendlyURI() + " modified: " + new Timestamp(lastModified).toString() + " length: " + fileObject.getContent().getSize());
}
if (deleteRecordFileObject(fileObject)) {
deleteIdSet.add(identifier);
} else {
LOG.warn("Failed to delete old file " + fileObject.getName().getFriendlyURI());
}
}
}
}
}
}
use of org.apache.commons.vfs2.FileType in project jackrabbit by apache.
the class VFSUtils method getChildrenOfTypes.
private static List<FileObject> getChildrenOfTypes(FileObject folderObject, Set<FileType> fileTypes) throws DataStoreException {
try {
String folderBaseName = folderObject.getName().getBaseName();
FileObject[] children = folderObject.getChildren();
List<FileObject> files = new ArrayList<FileObject>(children.length);
String childBaseName;
for (int i = 0; i < children.length; i++) {
childBaseName = children[i].getName().getBaseName();
FileType fileType = null;
try {
fileType = children[i].getType();
} catch (FileSystemException notDetermineTypeEx) {
if (folderBaseName.equals(childBaseName)) {
// Ignore this case.
// Some WebDAV server or VFS seems to include the folder itself as child as imaginary file type,
// and throw FileSystemException saying "Could not determine the type of file" in this case.
} else {
throw notDetermineTypeEx;
}
}
if (fileType != null && fileTypes.contains(fileType)) {
files.add(children[i]);
}
}
return files;
} catch (FileSystemException e) {
throw new DataStoreException("Could not find children under " + folderObject.getName().getFriendlyURI(), e);
}
}
Aggregations