use of org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.EMPTY_FILE in project studio by craftercms.
the class GitContentRepository method deleteParentFolder.
private String deleteParentFolder(Git git, Path parentFolder, boolean wasPage) throws GitAPIException, IOException {
String parent = parentFolder.toString();
String toRet = parent;
try {
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
String folderToDelete = helper.getGitPath(parent);
Path toDelete = Paths.get(git.getRepository().getDirectory().getParent(), parent);
if (Files.exists(toDelete)) {
List<String> dirs = Files.walk(toDelete).filter(x -> !x.equals(toDelete)).filter(Files::isDirectory).map(y -> y.getFileName().toString()).collect(Collectors.toList());
List<String> files = Files.walk(toDelete, 1).filter(x -> !x.equals(toDelete)).filter(Files::isRegularFile).map(y -> y.getFileName().toString()).collect(Collectors.toList());
if (wasPage || (CollectionUtils.isEmpty(dirs) && (CollectionUtils.isEmpty(files) || files.size() < 2 && files.get(0).equals(EMPTY_FILE)))) {
if (CollectionUtils.isNotEmpty(dirs)) {
for (String child : dirs) {
Path childToDelete = Paths.get(folderToDelete, child);
deleteParentFolder(git, childToDelete, false);
RmCommand rmCommand = git.rm().addFilepattern(folderToDelete + FILE_SEPARATOR + child + FILE_SEPARATOR + "*").setCached(false);
retryingRepositoryOperationFacade.call(rmCommand);
}
}
if (CollectionUtils.isNotEmpty(files)) {
for (String child : files) {
RmCommand rmCommand = git.rm().addFilepattern(folderToDelete + FILE_SEPARATOR + child).setCached(false);
retryingRepositoryOperationFacade.call(rmCommand);
}
}
}
}
} catch (CryptoException e) {
logger.error("Error deleting parent folder " + parentFolder.toString(), e);
}
return toRet;
}
use of org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.EMPTY_FILE in project studio by craftercms.
the class GitContentRepository method deleteParentFolder.
private String deleteParentFolder(Git git, Path parentFolder, boolean wasPage) throws GitAPIException, CryptoException, IOException {
String parent = parentFolder.toString();
String toRet = parent;
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
String folderToDelete = helper.getGitPath(parent);
Path toDelete = Paths.get(git.getRepository().getDirectory().getParent(), parent);
if (toDelete.toFile().exists()) {
List<String> dirs = Files.walk(toDelete).filter(x -> !x.equals(toDelete)).filter(Files::isDirectory).map(y -> y.getFileName().toString()).collect(Collectors.toList());
List<String> files = Files.walk(toDelete, 1).filter(x -> !x.equals(toDelete)).filter(Files::isRegularFile).map(y -> y.getFileName().toString()).collect(Collectors.toList());
if (wasPage || (CollectionUtils.isEmpty(dirs) && (CollectionUtils.isEmpty(files) || files.size() < 2 && files.get(0).equals(EMPTY_FILE)))) {
if (CollectionUtils.isNotEmpty(dirs)) {
for (String child : dirs) {
Path childToDelete = Paths.get(folderToDelete, child);
deleteParentFolder(git, childToDelete, false);
RmCommand rmCommand = git.rm().addFilepattern(folderToDelete + FILE_SEPARATOR + child + FILE_SEPARATOR + "*").setCached(false);
retryingRepositoryOperationFacade.call(rmCommand);
}
}
if (CollectionUtils.isNotEmpty(files)) {
for (String child : files) {
git.rm().addFilepattern(folderToDelete + FILE_SEPARATOR + child).setCached(false).call();
}
}
}
}
return toRet;
}
Aggregations