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

Directory Watcher does not match excluded sub directories on Windows

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Neutral
    • Resolution: Fixed
    • Affects Version/s: 5.5.6
    • Fix Version/s: 5.5.8, 5.6
    • Component/s: resource-loader
    • Labels:
      None
    • Environment:
      Windows 10
    • Testcase included:
      Yes
    • Sprint:
      Kromeriz 119
    • Story Points:
      2
    • Magnolia Release:
      5.5.8, 5.6

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

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Date of First Response: