Skip to content

Commit

Permalink
Merge pull request #16494 from iterate-ch/bugfix/MD-22410-refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
dkocher authored Nov 6, 2024
2 parents 918c983 + 1ccd382 commit 5e1d091
Show file tree
Hide file tree
Showing 42 changed files with 115 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.NotfoundException;
import ch.cyberduck.core.features.AclPermission;
import ch.cyberduck.core.shared.DefaultAclFeature;
import ch.cyberduck.core.transfer.TransferStatus;

import org.jets3t.service.acl.Permission;
Expand Down Expand Up @@ -55,7 +54,7 @@
* <p/>
* No public read access: Container and blob data can be read by the account owner only.
*/
public class AzureAclPermissionFeature extends DefaultAclFeature implements AclPermission {
public class AzureAclPermissionFeature implements AclPermission {

private final AzureSession session;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import ch.cyberduck.core.DirectoryDelimiterPathContainerService;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.PathContainerService;
import ch.cyberduck.core.exception.BackgroundException;
Expand Down Expand Up @@ -58,7 +57,7 @@ public AzureMetadataFeature(final AzureSession session, final OperationContext c
}

@Override
public Map<String, String> getDefault(final Local local) {
public Map<String, String> getDefault() {
return new HostPreferences(session.getHost()).getMap("azure.metadata.default");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import ch.cyberduck.core.features.AclPermission;
import ch.cyberduck.core.features.Location;
import ch.cyberduck.core.preferences.HostPreferences;
import ch.cyberduck.core.shared.DefaultAclFeature;
import ch.cyberduck.core.transfer.TransferStatus;

import org.jets3t.service.acl.Permission;
Expand All @@ -40,7 +39,7 @@
import synapticloop.b2.exception.B2ApiException;
import synapticloop.b2.response.B2BucketResponse;

public class B2BucketTypeFeature extends DefaultAclFeature implements AclPermission, Location {
public class B2BucketTypeFeature implements AclPermission, Location {

private final PathContainerService containerService
= new B2PathContainerService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.Headers;
Expand All @@ -39,7 +38,7 @@ public B2MetadataFeature(final B2Session session, final B2VersionIdProvider file
}

@Override
public Map<String, String> getDefault(final Local file) {
public Map<String, String> getDefault() {
return new HostPreferences(session.getHost()).getMap("b2.metadata.default");
}

Expand Down
40 changes: 31 additions & 9 deletions core/src/main/java/ch/cyberduck/core/features/AclPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.AbstractPath;
import ch.cyberduck.core.Acl;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Permission;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.preferences.Preferences;
import ch.cyberduck.core.preferences.PreferencesFactory;
import ch.cyberduck.core.transfer.TransferStatus;

import java.util.EnumSet;
Expand Down Expand Up @@ -63,16 +66,35 @@ default void setPermission(Path file, Acl acl) throws BackgroundException {
*/
List<Acl.Role> getAvailableAclRoles(List<Path> files);

Preferences preferences = PreferencesFactory.get();

/**
* @param file Remote file
* @param local File on local disk
* @param file Remote file
* @return Default ACL to set for file
*/
Acl getDefault(Path file, Local local) throws BackgroundException;
default Acl getDefault(final Path type) throws BackgroundException {
if(preferences.getBoolean("queue.upload.permissions.default")) {
if(type.getType().contains(Path.Type.file)) {
return toAcl(new Permission(preferences.getInteger("queue.upload.permissions.file.default")));
}
else {
return toAcl(new Permission(preferences.getInteger("queue.upload.permissions.folder.default")));
}
}
return Acl.EMPTY;
}

/**
* @param type File or folder
* @return Default ACL for new file or folder
*/
Acl getDefault(EnumSet<Path.Type> type) throws BackgroundException;
static Acl toAcl(final Permission permission) {
final Acl acl = new Acl();
if(permission.getOther().implies(Permission.Action.read)) {
acl.addAll(new Acl.GroupUser(Acl.GroupUser.EVERYONE), new Acl.Role(Acl.Role.READ));
}
if(permission.getGroup().implies(Permission.Action.read)) {
acl.addAll(new Acl.GroupUser(Acl.GroupUser.AUTHENTICATED), new Acl.Role(Acl.Role.READ));
}
if(permission.getGroup().implies(Permission.Action.write)) {
acl.addAll(new Acl.GroupUser(Acl.GroupUser.AUTHENTICATED), new Acl.Role(Acl.Role.WRITE));
}
return acl;
}
}
3 changes: 1 addition & 2 deletions core/src/main/java/ch/cyberduck/core/features/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.transfer.TransferStatus;
Expand All @@ -24,7 +23,7 @@

@Optional
public interface Metadata {
Map<String, String> getDefault(Local local);
Map<String, String> getDefault();

Map<String, String> getMetadata(Path file) throws BackgroundException;

Expand Down
68 changes: 0 additions & 68 deletions core/src/main/java/ch/cyberduck/core/shared/DefaultAclFeature.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Headers;
import ch.cyberduck.core.transfer.TransferStatus;
Expand All @@ -25,7 +24,7 @@

public class DisabledHeadersFeature implements Headers {
@Override
public Map<String, String> getDefault(final Local local) {
public Map<String, String> getDefault() {
return Collections.emptyMap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ public TransferStatus prepare(final Path file, final Local n, final TransferStat
catch(NotfoundException | AccessDeniedException | InteroperabilityException e) {
final AclPermission targetFeature = targetSession.getFeature(AclPermission.class);
if(targetFeature != null) {
status.setAcl(targetFeature.getDefault(file.getType()));
status.setAcl(targetFeature.getDefault(file));
}
}
}
else {
final AclPermission targetFeature = targetSession.getFeature(AclPermission.class);
if(targetFeature != null) {
status.setAcl(targetFeature.getDefault(file.getType()));
status.setAcl(targetFeature.getDefault(file));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ public TransferStatus prepare(final Path file, final Local local, final Transfer
// Look if there is directory or file that clashes with this upload
if(file.getType().contains(Path.Type.file)) {
if(find.find(new Path(file.getAbsolute(), EnumSet.of(Path.Type.directory)))) {
throw new AccessDeniedException(String.format("Cannot replace folder %s with file %s", file.getAbsolute(), local.getName()));
throw new AccessDeniedException(String.format("Cannot replace folder %s with file %s", file.getAbsolute(), file.getName()));
}
}
if(file.getType().contains(Path.Type.directory)) {
if(find.find(new Path(file.getAbsolute(), EnumSet.of(Path.Type.file)))) {
throw new AccessDeniedException(String.format("Cannot replace file %s with folder %s", file.getAbsolute(), local.getName()));
throw new AccessDeniedException(String.format("Cannot replace file %s with folder %s", file.getAbsolute(), file.getName()));
}
}
}
Expand Down Expand Up @@ -201,11 +201,11 @@ public TransferStatus prepare(final Path file, final Local local, final Transfer
status.setAcl(feature.getPermission(file));
}
catch(NotfoundException | AccessDeniedException | InteroperabilityException e) {
status.setAcl(feature.getDefault(file, local));
status.setAcl(feature.getDefault(file));
}
}
else {
status.setAcl(feature.getDefault(file, local));
status.setAcl(feature.getDefault(file));
}
}
else {
Expand All @@ -231,11 +231,11 @@ public TransferStatus prepare(final Path file, final Local local, final Transfer
status.setMetadata(feature.getMetadata(file));
}
catch(NotfoundException | AccessDeniedException | InteroperabilityException e) {
status.setMetadata(feature.getDefault(local));
status.setMetadata(feature.getDefault());
}
}
else {
status.setMetadata(feature.getDefault(local));
status.setMetadata(feature.getDefault());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.AbstractPath;
import ch.cyberduck.core.Acl;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.exception.BackgroundException;
Expand Down Expand Up @@ -60,13 +60,8 @@ public List<Acl.Role> getAvailableAclRoles(final List<Path> files) {
}

@Override
public Acl getDefault(final Path file, final Local local) throws BackgroundException {
return proxy.getDefault(file, local);
}

@Override
public Acl getDefault(final EnumSet<Path.Type> type) throws BackgroundException {
return proxy.getDefault(type);
public Acl getDefault(final Path file) throws BackgroundException {
return proxy.getDefault(file);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Local;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.Session;
import ch.cyberduck.core.exception.BackgroundException;
Expand All @@ -38,8 +37,8 @@ public VaultRegistryHeadersFeature(final Session<?> session, final Headers proxy
}

@Override
public Map<String, String> getDefault(final Local local) {
return proxy.getDefault(local);
public Map<String, String> getDefault() {
return proxy.getDefault();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Path run(final Session<?> session) throws BackgroundException {
}
final AclPermission acl = session.getFeature(AclPermission.class);
if(acl != null) {
status.setAcl(acl.getDefault(EnumSet.of(Path.Type.directory)));
status.setAcl(acl.getDefault(folder));
}
}
status.setRegion(region);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Path run(final Session<?> session) throws BackgroundException {
}
final AclPermission acl = session.getFeature(AclPermission.class);
if(acl != null) {
status.setAcl(acl.getDefault(EnumSet.of(Path.Type.file)));
status.setAcl(acl.getDefault(file));
}
}
final Path result = feature.touch(file, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public WriteAclWorker(final List<Path> files,
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final AclPermission feature = session.getFeature(AclPermission.class);
if(null == feature) {
return false;
}
log.debug("Run with feature {}", feature);
for(Path file : files) {
this.write(session, feature, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public WriteDistributionWorker(final List<Path> files, final LoginCallback promp
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final DistributionConfiguration feature = session.getFeature(DistributionConfiguration.class);
if(null == feature) {
return false;
}
log.debug("Run with feature {}", feature);
final PathContainerService container = session.getFeature(PathContainerService.class);
for(Path file : this.getContainers(container, files)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public WriteEncryptionWorker(final List<Path> files, final Encryption.Algorithm
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final Encryption feature = session.getFeature(Encryption.class);
if(null == feature) {
return false;
}
log.debug("Run with feature {}", feature);
for(Path file : files) {
if(this.isCanceled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public WriteLifecycleWorker(final List<Path> files, final LifecycleConfiguration
@Override
public Boolean run(final Session<?> session) throws BackgroundException {
final Lifecycle feature = session.getFeature(Lifecycle.class);
if(null == feature) {
return false;
}
log.debug("Run with feature {}", feature);
final PathContainerService container = session.getFeature(PathContainerService.class);
for(Path file : this.getContainers(container, files)) {
Expand Down
Loading

0 comments on commit 5e1d091

Please sign in to comment.