Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-7139

Directory Watcher does not match excluded sub directories on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 5.5.8, 5.6
    • 5.5.6
    • resource-loader
    • None
    • Windows 10
    • Yes
    • Kromeriz 119
    • 2

      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($|[/\\].*)

        Acceptance criteria

              efochr Evzen Fochr
              sbach Sven Bach
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: