Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise application support directory migration. #16375

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@

import ch.cyberduck.core.Local;
import ch.cyberduck.core.exception.AccessDeniedException;
import ch.cyberduck.core.local.LocalSymlinkFactory;
import ch.cyberduck.core.local.LocalTrashFactory;
import ch.cyberduck.core.local.features.Symlink;
import ch.cyberduck.core.local.features.Trash;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.IOException;

public class MigratingSupportDirectoryFinder implements SupportDirectoryFinder {
private static final Logger log = LogManager.getLogger(MigratingSupportDirectoryFinder.class);

Expand All @@ -45,41 +37,27 @@ public MigratingSupportDirectoryFinder(final SupportDirectoryFinder deprecated,

@Override
public SupportDirectoryFinder setup() {
final Local previous = deprecated.find();
if(previous.exists()) {
if(previous.isSymbolicLink()) {
if(log.isDebugEnabled()) {
log.debug(String.format("Previous application support folder %s already symlink", previous));
}
}
else {
final Local folder = proxy.find().getParent();
final Local appdata = proxy.find();
if(appdata.exists()) {
log.debug(String.format("Application support folder %s already exists", appdata));
}
else {
final Local previous = deprecated.find();
if(previous.exists()) {
if(log.isWarnEnabled()) {
log.warn(String.format("Migrate application support folder from %s to %s", previous, folder));
log.warn(String.format("Migrate application support folder from %s to %s", previous, appdata));
}
// Rename folder recursively
try {
FileUtils.copyDirectory(new File(previous.getAbsolute()), new File(folder.getAbsolute()));
try {
final Trash trash = LocalTrashFactory.get();
if(log.isWarnEnabled()) {
log.warn(String.format("Trash previous application support folder %s", previous));
}
trash.trash(previous);
final Symlink symlink = LocalSymlinkFactory.get();
symlink.symlink(previous, folder.getAbsolute());
}
catch(AccessDeniedException e) {
log.warn(String.format("Failure %s creating symbolcic link for previous application support directory %s", e, previous));
}
// Rename folder recursively
previous.rename(appdata);
}
catch(IOException e) {
log.warn(String.format("Failure %s migrating %s to security application group directory %s", e, previous, folder));
catch(AccessDeniedException e) {
log.warn(String.format("Failure %s migrating %s to application group directory %s", e, previous, appdata));
}
}
}
else {
log.debug(String.format("No previous application support folder found in %s", previous));
else {
log.debug(String.format("No previous application support folder found in %s", previous));
}
}
return this;
}
Expand Down