[MAGNOLIA-7139] Directory Watcher does not match excluded sub directories on Windows Created: 15/Sep/17  Updated: 30/Oct/17  Resolved: 27/Oct/17

Status: Closed
Project: Magnolia
Component/s: resource-loader
Affects Version/s: 5.5.6
Fix Version/s: 5.5.8, 5.6

Type: Bug Priority: Neutral
Reporter: Sven Bach Assignee: Evzen Fochr
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10


Issue Links:
causality
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Testcase included:
Yes
Date of First Response:
Sprint: Kromeriz 119
Story Points: 2

 Description   

When working with light modules there are many directories watched which are not relevant.
This results in heavy DirectoryWatcher activity when doing git fetch or npm install.
So I extended the exclusion property:

magnolia.resources.filesystem.observation.excludedDirectories=META-INF,WEB-INF,cache,docroot,logs,repositories,tmp,.git,.idea,node_modules

The exclusions are applied, but are not matched by ExclusionsFilter if in subdirectories.

Simple test case:

public class ExclusionFilterTest {

    private Path rootPath;
    private ExclusionsFilter filter;

    @Before
    public void setup() {
        this.rootPath = Paths.get("C:/magnolia-resources-root");
        final List<String> configuredExcludedDirectories = Lists.newArrayList();
        configuredExcludedDirectories.add(".git");
        this.filter = new ExclusionsFilter(rootPath, configuredExcludedDirectories, Collections.emptyList(), Collections.emptyList());
    }

    @Test
    public void shouldNotAcceptExcludedDirectoryInRootPath() {
        final Path path = rootPath.resolve(".git");
        assertFalse("Should match .git in root", filter.apply(path));
    }

    @Test
    public void shouldNotAcceptExcludedDirectoryInSubPath() {
        final Path path = rootPath.resolve("light-module/.git");
        assertFalse("Should match .git in subdir", filter.apply(path));
    }
}

The second test fails on Windows because of the regex used in ExclusionsFilter.
The relevant code:

info.magnolia.resourceloader.file.ExclusionsFilter#apply

// This resolves to "light-module\.git" - notice the backslash
Path rel = rootPath.relativize(normalizedDir);

This does not match the regex

(^|.*/)\Q.git\E($|/.*)

.
It works if I modify the regex to

(^|.*[/\\])\Q.git\E($|[/\\].*)

Generated at Mon Feb 12 04:21:05 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.