[ 
https://issues.apache.org/jira/browse/NIFI-7950?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Francçois-Xavier HENG updated NIFI-7950:
----------------------------------------
    Description: 
On windows TailFile can not work for "Tailing mode" = Multiple files.

I'm not good enough with apache lib to correct this alone but here is the 
faulty part:
In 
nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java,
 line 409:
   /**
     * Method to list the files to tail according to the given base directory
     * and using the user-provided regular expression
     * @param baseDir base directory to recursively look into
     * @param fileRegex expression regular used to match files to tail
     * @param isRecursive true if looking for file recursively, false otherwise
     * @return List of files to tail
     */
    private List<String> getFilesToTail(final String baseDir, String fileRegex, 
boolean isRecursive, long maxAge) {
        final Collection<File> files = FileUtils.listFiles(new File(baseDir), 
null, isRecursive);
        final List<String> result = new ArrayList<String>();
        final String baseDirNoTrailingSeparator = 
baseDir.endsWith(File.separator) ? baseDir.substring(0, baseDir.length() - 1) : 
baseDir;
        final String fullRegex;
        if (File.separator.equals("/")) {
            // handle unix-style paths
            fullRegex = baseDirNoTrailingSeparator + File.separator + fileRegex;
        } else {
            // handle windows-style paths, need to quote backslash characters
            fullRegex = baseDirNoTrailingSeparator + 
Pattern.quote(File.separator) + fileRegex;
        }
        final Pattern p = Pattern.compile(fullRegex);

On windows the separator is the regexp exape char '\'. The windows path cannot 
be turn in a usable regexp.
Only workaround is to double slash the windows path after removing last 
trailing '\'.
Solution maybe to escape all separator in the variable 
baseDirNoTrailingSeparator.

  was:
On windows TailFile can not work for "Tailing mode" = Multiple files.

I'm not good enough with apache lib to correct this alone but here is the 
faulty part:
In 
nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java,
 line 409:
   _/**
     * Method to list the files to tail according to the given base directory
     * and using the user-provided regular expression
     * @param baseDir base directory to recursively look into
     * @param fileRegex expression regular used to match files to tail
     * @param isRecursive true if looking for file recursively, false otherwise
     * @return List of files to tail
     */_
    private List<String> getFilesToTail(final String baseDir, String fileRegex, 
boolean isRecursive, long maxAge) {
        final Collection<File> files = FileUtils.listFiles(new File(baseDir), 
null, isRecursive);
        final List<String> result = new ArrayList<String>();
        final String baseDirNoTrailingSeparator = 
baseDir.endsWith(File.separator) ? baseDir.substring(0, baseDir.length() - 1) : 
baseDir;
        final String fullRegex;
        if (File.separator.equals("/")) {
            // handle unix-style paths
            fullRegex = baseDirNoTrailingSeparator + File.separator + fileRegex;
        } else {
            // handle windows-style paths, need to quote backslash characters
            fullRegex = baseDirNoTrailingSeparator + 
Pattern.quote(File.separator) + fileRegex;
        }
        final Pattern p = Pattern.compile(fullRegex);

On windows the separator is the regexp exape char '\'. The windows path cannot 
be turn in a usable regexp.
Only workaround is to double slash the windows path after removing last 
trailing '\'.
Solution maybe to escape all separator in the variable 
baseDirNoTrailingSeparator.


> TailFile processor in Multiple files mode cannot work on Windows.
> -----------------------------------------------------------------
>
>                 Key: NIFI-7950
>                 URL: https://issues.apache.org/jira/browse/NIFI-7950
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 1.11.4, 1.12.1
>         Environment: Windows
>            Reporter: Francçois-Xavier HENG
>            Priority: Major
>              Labels: easyfix
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> On windows TailFile can not work for "Tailing mode" = Multiple files.
> I'm not good enough with apache lib to correct this alone but here is the 
> faulty part:
> In 
> nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java,
>  line 409:
>    /**
>      * Method to list the files to tail according to the given base directory
>      * and using the user-provided regular expression
>      * @param baseDir base directory to recursively look into
>      * @param fileRegex expression regular used to match files to tail
>      * @param isRecursive true if looking for file recursively, false 
> otherwise
>      * @return List of files to tail
>      */
>     private List<String> getFilesToTail(final String baseDir, String 
> fileRegex, boolean isRecursive, long maxAge) {
>         final Collection<File> files = FileUtils.listFiles(new File(baseDir), 
> null, isRecursive);
>         final List<String> result = new ArrayList<String>();
>         final String baseDirNoTrailingSeparator = 
> baseDir.endsWith(File.separator) ? baseDir.substring(0, baseDir.length() - 1) 
> : baseDir;
>         final String fullRegex;
>         if (File.separator.equals("/")) {
>             // handle unix-style paths
>             fullRegex = baseDirNoTrailingSeparator + File.separator + 
> fileRegex;
>         } else {
>             // handle windows-style paths, need to quote backslash characters
>             fullRegex = baseDirNoTrailingSeparator + 
> Pattern.quote(File.separator) + fileRegex;
>         }
>         final Pattern p = Pattern.compile(fullRegex);
> On windows the separator is the regexp exape char '\'. The windows path 
> cannot be turn in a usable regexp.
> Only workaround is to double slash the windows path after removing last 
> trailing '\'.
> Solution maybe to escape all separator in the variable 
> baseDirNoTrailingSeparator.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to