Skip to content

Commit

Permalink
CAMEL-21282: camel-file - Add option to create dir in stepwise mode. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus authored Sep 30, 2024
1 parent 7ed00da commit 1f1fa4d
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 117 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "appendChars": target.setAppendChars(property(camelContext, java.lang.String.class, value)); return true;
case "autocreate":
case "autoCreate": target.setAutoCreate(property(camelContext, boolean.class, value)); return true;
case "autocreatestepwise":
case "autoCreateStepwise": target.setAutoCreateStepwise(property(camelContext, boolean.class, value)); return true;
case "backofferrorthreshold":
case "backoffErrorThreshold": target.setBackoffErrorThreshold(property(camelContext, int.class, value)); return true;
case "backoffidlethreshold":
Expand Down Expand Up @@ -221,6 +223,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "appendChars": return java.lang.String.class;
case "autocreate":
case "autoCreate": return boolean.class;
case "autocreatestepwise":
case "autoCreateStepwise": return boolean.class;
case "backofferrorthreshold":
case "backoffErrorThreshold": return int.class;
case "backoffidlethreshold":
Expand Down Expand Up @@ -408,6 +412,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "appendChars": return target.getAppendChars();
case "autocreate":
case "autoCreate": return target.isAutoCreate();
case "autocreatestepwise":
case "autoCreateStepwise": return target.isAutoCreateStepwise();
case "backofferrorthreshold":
case "backoffErrorThreshold": return target.getBackoffErrorThreshold();
case "backoffidlethreshold":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public class FileEndpointUriFactory extends org.apache.camel.support.component.E
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
Set<String> props = new HashSet<>(99);
Set<String> props = new HashSet<>(100);
props.add("allowNullBody");
props.add("antExclude");
props.add("antFilterCaseSensitive");
props.add("antInclude");
props.add("appendChars");
props.add("autoCreate");
props.add("autoCreateStepwise");
props.add("backoffErrorThreshold");
props.add("backoffIdleThreshold");
props.add("backoffMultiplier");
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
@UriPath(name = "directoryName")
@Metadata(required = true)
private File file;
@UriParam(label = "advanced")
protected boolean autoCreateStepwise;
@UriParam(label = "advanced", defaultValue = "true")
private boolean copyAndDeleteOnRenameFail = true;
@UriParam(label = "advanced")
Expand Down Expand Up @@ -288,6 +290,18 @@ public boolean isHiddenFilesEnabled() {
return includeHiddenFiles;
}

public boolean isAutoCreateStepwise() {
return autoCreateStepwise;
}

/**
* When auto-creating directories should each subdirectory be created one at a time. This may be needed due to
* security issues on some file-shares.
*/
public void setAutoCreateStepwise(boolean autoCreateStepwise) {
this.autoCreateStepwise = autoCreateStepwise;
}

public boolean isCopyAndDeleteOnRenameFail() {
return copyAndDeleteOnRenameFail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public boolean existsFile(String name) throws GenericFileOperationFailedExceptio
return file.exists();
}

protected boolean buildDirectory(File dir, Set<PosixFilePermission> permissions, boolean absolute) {
protected boolean buildDirectory(File dir, Set<PosixFilePermission> permissions, boolean absolute, boolean stepwise) {
if (dir.exists()) {
return true;
}

if (permissions == null || permissions.isEmpty()) {
if (!stepwise && (permissions == null || permissions.isEmpty())) {
return dir.mkdirs();
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public boolean buildDirectory(String directory, boolean absolute) throws Generic
// always create endpoint defined directory
if (endpoint.isAutoCreate() && !endpoint.getFile().exists()) {
LOG.trace("Building starting directory: {}", endpoint.getFile());
buildDirectory(endpoint.getFile(), endpoint.getDirectoryPermissions(), absolute);
buildDirectory(endpoint.getFile(), endpoint.getDirectoryPermissions(), absolute, endpoint.isAutoCreateStepwise());
}

if (ObjectHelper.isEmpty(directory)) {
Expand Down Expand Up @@ -199,7 +199,7 @@ public boolean buildDirectory(String directory, boolean absolute) throws Generic
return true;
} else {
LOG.trace("Building directory: {}", path);
return buildDirectory(path, endpoint.getDirectoryPermissions(), absolute);
return buildDirectory(path, endpoint.getDirectoryPermissions(), absolute, endpoint.isAutoCreateStepwise());
}
} finally {
lock.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,40 @@ default AdvancedFileEndpointConsumerBuilder autoCreate(String autoCreate) {
doSetProperty("autoCreate", autoCreate);
return this;
}
/**
* When auto-creating directories should each subdirectory be created
* one at a time. This may be needed due to security issues on some
* file-shares.
*
* The option is a: <code>boolean</code> type.
*
* Default: false
* Group: advanced
*
* @param autoCreateStepwise the value to set
* @return the dsl builder
*/
default AdvancedFileEndpointConsumerBuilder autoCreateStepwise(boolean autoCreateStepwise) {
doSetProperty("autoCreateStepwise", autoCreateStepwise);
return this;
}
/**
* When auto-creating directories should each subdirectory be created
* one at a time. This may be needed due to security issues on some
* file-shares.
*
* The option will be converted to a <code>boolean</code> type.
*
* Default: false
* Group: advanced
*
* @param autoCreateStepwise the value to set
* @return the dsl builder
*/
default AdvancedFileEndpointConsumerBuilder autoCreateStepwise(String autoCreateStepwise) {
doSetProperty("autoCreateStepwise", autoCreateStepwise);
return this;
}
/**
* Maximum number of messages to keep in memory available for browsing.
* Use 0 for unlimited.
Expand Down Expand Up @@ -3341,6 +3375,40 @@ default AdvancedFileEndpointProducerBuilder autoCreate(String autoCreate) {
doSetProperty("autoCreate", autoCreate);
return this;
}
/**
* When auto-creating directories should each subdirectory be created
* one at a time. This may be needed due to security issues on some
* file-shares.
*
* The option is a: <code>boolean</code> type.
*
* Default: false
* Group: advanced
*
* @param autoCreateStepwise the value to set
* @return the dsl builder
*/
default AdvancedFileEndpointProducerBuilder autoCreateStepwise(boolean autoCreateStepwise) {
doSetProperty("autoCreateStepwise", autoCreateStepwise);
return this;
}
/**
* When auto-creating directories should each subdirectory be created
* one at a time. This may be needed due to security issues on some
* file-shares.
*
* The option will be converted to a <code>boolean</code> type.
*
* Default: false
* Group: advanced
*
* @param autoCreateStepwise the value to set
* @return the dsl builder
*/
default AdvancedFileEndpointProducerBuilder autoCreateStepwise(String autoCreateStepwise) {
doSetProperty("autoCreateStepwise", autoCreateStepwise);
return this;
}
/**
* Maximum number of messages to keep in memory available for browsing.
* Use 0 for unlimited.
Expand Down Expand Up @@ -3646,6 +3714,40 @@ default AdvancedFileEndpointBuilder autoCreate(String autoCreate) {
doSetProperty("autoCreate", autoCreate);
return this;
}
/**
* When auto-creating directories should each subdirectory be created
* one at a time. This may be needed due to security issues on some
* file-shares.
*
* The option is a: <code>boolean</code> type.
*
* Default: false
* Group: advanced
*
* @param autoCreateStepwise the value to set
* @return the dsl builder
*/
default AdvancedFileEndpointBuilder autoCreateStepwise(boolean autoCreateStepwise) {
doSetProperty("autoCreateStepwise", autoCreateStepwise);
return this;
}
/**
* When auto-creating directories should each subdirectory be created
* one at a time. This may be needed due to security issues on some
* file-shares.
*
* The option will be converted to a <code>boolean</code> type.
*
* Default: false
* Group: advanced
*
* @param autoCreateStepwise the value to set
* @return the dsl builder
*/
default AdvancedFileEndpointBuilder autoCreateStepwise(String autoCreateStepwise) {
doSetProperty("autoCreateStepwise", autoCreateStepwise);
return this;
}
/**
* Maximum number of messages to keep in memory available for browsing.
* Use 0 for unlimited.
Expand Down

0 comments on commit 1f1fa4d

Please sign in to comment.