camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Damyan Damyanov (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAMEL-11298) Using chmodDirectory with full paths makes file producer to created directories relative to source
Date Sat, 20 May 2017 09:29:04 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-11298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16017874#comment-16017874
] 

Damyan Damyanov edited comment on CAMEL-11298 at 5/20/17 9:28 AM:
------------------------------------------------------------------

Sure, this route below will produce an exception that illustrates the problem, the chmodDirectory
property will create the directory relative to the source but the file producer will look
for that directory in its system path resulting in a FileNotFoundException.

{code}
@Component
public class TestRouter extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        String outputFileDir = "/home/damyan/Desktop/test/test2/";

        from("timer://foo?fixedRate=true&period=10000")
                .setBody(simple ("Hello World"))
                .to("file://" + outputFileDir + "?chmodDirectory=777");
    }
}
{code}


was (Author: stabbz):
Sure, this route below will produce an exception that illustrates the problem, the chmodDirectory
property will create the directory relative to the source but the file producer will look
for that directory in its system path resulting in a FileNotFoundException.

{code}
@Component
public class TestRouter extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        String outputFileDir = "/home/damyan/Desktop/test/test2/";

        from("timer://foo?fixedRate=true&period=10000")
                .setBody(simple ("Hello World"))
                .toD("file://" + outputFileDir + "?chmodDirectory=777");
    }
}
{code}

> Using chmodDirectory with full paths makes file producer to created directories relative
to source
> --------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-11298
>                 URL: https://issues.apache.org/jira/browse/CAMEL-11298
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.18.2, 2.19.0
>         Environment: Arch Linux
>            Reporter: Damyan Damyanov
>
> Tried using the chmodDirectory property on a file producer that writes to full system
paths and noticed that with the chmodDirectory property the directories get created relative
to the source/project.
> Without using the property the files get properly created using the full path that is
given to them.
> I ran a debugger and found the source of the problem:
> Code is from org.apache.camel.component.file.FileOperations 
> in buildDirectory method
> at lines 97 - 118
> {code}
> if (permissions == null || permissions.isEmpty()) {
>             return dir.mkdirs();
>         }
>         // create directory one part of a time and set permissions
>         try {
>             String[] parts = dir.getPath().split("\\" + File.separatorChar);
>             File base = new File(".");
>             for (String part : parts) {
>                 File subDir = new File(base, part);
>                 if (!subDir.exists()) {
>                     if (subDir.mkdir()) {
>                         if (LOG.isTraceEnabled()) {
>                             LOG.trace("Setting chmod: {} on directory: {} ", PosixFilePermissions.toString(permissions),
subDir);
>                         }
>                         Files.setPosixFilePermissions(subDir.toPath(), permissions);
>                     } else {
>                         return false;
>                     }
>                 }
>                 base = new File(base, subDir.getName());
>             }
>         }
> {code}
> Base File used to create all the folders and set their permissions is initialized with
new File("."), effectively this always creates the directories given to it, relative to the
source, and will not handle full system paths.
> Is there a reason I'm unaware of that this is implemented this way?
> I tested running folder creation code with new File("") as a base and it worked fine,
would that be enough to handle the issue if it indeed is an issue?
> I can do this my self by issuing a pull request, let me know.
> Thanks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message