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

Fix #15250. #15251

Merged
merged 8 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions cli/src/main/java/ch/cyberduck/cli/TerminalPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package ch.cyberduck.cli;

import ch.cyberduck.core.DisabledConnectionTimeout;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.Permission;
import ch.cyberduck.core.cryptomator.CryptoVault;
import ch.cyberduck.core.cryptomator.random.FastSecureRandomProvider;
Expand Down Expand Up @@ -46,6 +47,7 @@ public TerminalPreferences(final Preferences persistence) {
protected void setFactories() {
super.setFactories();

this.setDefault("factory.local.class", Local.class.getName());
this.setDefault("factory.certificatestore.class", TerminalCertificateStore.class.getName());
this.setDefault("factory.logincallback.class", TerminalLoginCallback.class.getName());
this.setDefault("factory.passwordcallback.class", TerminalPasswordCallback.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ protected void setFactories() {
this.setDefault("factory.badgelabeler.class", WorkspaceApplicationBadgeLabeler.class.getName());
this.setDefault("factory.watchservice.class", FSEventWatchService.class.getName());
this.setDefault("factory.editorfactory.class", FSEventWatchEditorFactory.class.getName());
if(null == this.getDefault("SUExpectsDSASignature")) {
this.setDefault("factory.licensefactory.class", ReceiptFactory.class.getName());
}
this.setDefault("factory.notification.class", NotificationCenter.class.getName());
this.setDefault("factory.iconservice.class", WorkspaceIconService.class.getName());
this.setDefault("factory.filedescriptor.class", LaunchServicesFileDescriptor.class.getName());
Expand All @@ -122,4 +119,12 @@ protected void setFactories() {
this.setDefault("factory.urlfilewriter.class", WeblocFileWriter.class.getName());
this.setDefault("factory.quicklook.class", QuartzQuickLook.class.getName());
}

@Override
protected void setDefaults() {
super.setDefaults();
if(null == this.getDefault("SUExpectsDSASignature")) {
this.setDefault("factory.licensefactory.class", ReceiptFactory.class.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
public class UserDefaultsPreferences extends DefaultPreferences {
private static final Logger log = LogManager.getLogger(UserDefaultsPreferences.class);

private final NSBundle bundle = new BundleApplicationResourcesFinder().bundle();

private final LRUCache<String, String> cache = LRUCache.usingLoader(this::loadProperty,
PreferencesFactory.get().getLong("preferences.cache.size"));
private final LRUCache<String, String> cache = LRUCache.usingLoader(this::loadProperty, 1000);

private static final String MISSING_PROPERTY = String.valueOf(StringUtils.INDEX_NOT_FOUND);

Expand All @@ -73,6 +70,7 @@ public String getDefault(final String property) {
// Lookup in the default map
final String value = super.getDefault(property);
if(null == value) {
final NSBundle bundle = new BundleApplicationResourcesFinder().bundle();
// Missing in default. Lookup in Info.plist
NSObject plist = bundle.infoDictionary().objectForKey(property);
if(null == plist) {
Expand Down Expand Up @@ -171,6 +169,7 @@ protected void setDefaults() {
this.setDefault("local.user.home", SystemB.INSTANCE.getpwuid(LibC.INSTANCE.getuid()).pw_dir);
}

final NSBundle bundle = new BundleApplicationResourcesFinder().bundle();
if(null != bundle) {
if(bundle.objectForInfoDictionaryKey("CFBundleName") != null) {
this.setDefault("application.name", bundle.objectForInfoDictionaryKey("CFBundleName").toString());
Expand Down Expand Up @@ -273,6 +272,7 @@ public String locale() {

@Override
public List<String> applicationLocales() {
final NSBundle bundle = new BundleApplicationResourcesFinder().bundle();
return this.toList(bundle.localizations());
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/ch/cyberduck/core/Local.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ private static FileChannel getWriteChannel(final String path, final boolean appe
}

public Object lock(final boolean interactive) throws AccessDeniedException {
if(log.isWarnEnabled()) {
log.warn(String.format("No lock support in %s", this));
}
return null;
}

Expand Down
22 changes: 22 additions & 0 deletions core/src/main/java/ch/cyberduck/core/LocalFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import ch.cyberduck.core.preferences.PreferencesFactory;

import org.apache.commons.lang3.reflect.ConstructorUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public final class LocalFactory extends Factory<Local> {
private static final Logger log = LogManager.getLogger(LocalFactory.class);

private Constructor<? extends Local> constructorCreateFromString;
private Constructor<? extends Local> constructorCreateFromParentString;
Expand All @@ -43,6 +46,9 @@ private Local create(final String path) {
try {
if(null == constructorCreateFromString) {
constructorCreateFromString = ConstructorUtils.getMatchingAccessibleConstructor(clazz, String.class);
if(log.isWarnEnabled()) {
log.warn(String.format("Caching constructor %s for class %s", constructorCreateFromString, clazz));
}
}
return constructorCreateFromString.newInstance(path);
}
Expand All @@ -55,6 +61,9 @@ private Local create(final Local parent, final String path) {
try {
if(null == constructorCreateFromParentString) {
constructorCreateFromParentString = ConstructorUtils.getMatchingAccessibleConstructor(clazz, parent.getClass(), path.getClass());
if(log.isWarnEnabled()) {
log.warn(String.format("Caching constructor %s for class %s", constructorCreateFromParentString, clazz));
}
}
return constructorCreateFromParentString.newInstance(parent, path);
}
Expand All @@ -68,27 +77,40 @@ private Local create(final Local parent, final String path) {
public static synchronized Local get(final Local parent, final String name) {
if(null == singleton) {
singleton = new LocalFactory();
if(log.isDebugEnabled()) {
log.debug(String.format("Using implementation %s", singleton.getClass()));
}

}
return singleton.create(parent, name);
}

public static synchronized Local get(final String parent, final String name) {
if(null == singleton) {
singleton = new LocalFactory();
if(log.isDebugEnabled()) {
log.debug(String.format("Using implementation %s", singleton.getClass()));
}
}
return singleton.create(singleton.create(parent), name);
}

public static synchronized Local get(final String path) {
if(null == singleton) {
singleton = new LocalFactory();
if(log.isDebugEnabled()) {
log.debug(String.format("Using implementation %s", singleton.getClass()));
}
}
return singleton.create(path);
}

public static synchronized Local get() {
if(null == singleton) {
singleton = new LocalFactory();
if(log.isDebugEnabled()) {
log.debug(String.format("Using implementation %s", singleton.getClass()));
}
}
return singleton.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package ch.cyberduck.core.preferences;

import ch.cyberduck.core.Local;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -60,4 +62,11 @@ public List<String> applicationLocales() {
public List<String> systemLocales() {
return Collections.singletonList("en");
}

@Override
protected void setFactories() {
super.setFactories();

this.setDefault("factory.local.class", Local.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ protected void setFactories() {
this.setDefault("factory.writer.host.class", PlistWriter.class.getName());

this.setDefault("factory.locale.class", DisabledLocale.class.getName());
this.setDefault("factory.local.class", Local.class.getName());
this.setDefault("factory.certificatestore.class", DisabledCertificateStore.class.getName());
this.setDefault("factory.logincallback.class", DisabledLoginCallback.class.getName());
this.setDefault("factory.passwordcallback.class", DisabledPasswordCallback.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.logging.log4j.Logger;

public final class PreferencesFactory {
private static final Logger log = LogManager.getLogger(PreferencesFactory.class);

private PreferencesFactory() {
//
}
Expand All @@ -46,6 +48,7 @@ public static synchronized void set(final Preferences p) {

public static synchronized Preferences get() {
if(null == preferences) {
log.error("No application preferences registered");
set(new MemoryPreferences());
}
return preferences;
Expand Down
1 change: 0 additions & 1 deletion defaults/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ profiles.discovery.updater.url=s3://profiles.cyberduck.io
browser.cache.size=1000
transfer.cache.size=100
icon.cache.size=200
preferences.cache.size=1000
fileid.cache.size=10000

# Caching NS* proxy instances.
Expand Down