Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.nio.file.InvalidPathException when copying a repo that had a file with an invalid character in its name in Windows #234

Open
g-ortuno opened this issue May 11, 2023 · 0 comments

Comments

@g-ortuno
Copy link

g-ortuno commented May 11, 2023

If a file had an invalid character in its name at some point, then copybara will fail to copy the repo if the workflow specifies origin_files.

I made a repo to reproduce the issue; it also has a copy.bara.sky file that repros the issue. There's a file there, file with less-than and greater than.txt, that used to be called file with <>.txt. The file has since been renamed but trying to copybara the repo still fails.

Stacktrace:

java.nio.file.InvalidPathException: Illegal char <<> at index 11: /file with <>.txt
        at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
        at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
        at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
        at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232)
        at java.base/java.nio.file.Path.of(Path.java:148)
        at java.base/java.nio.file.Paths.get(Paths.java:69)
        at com.google.copybara.WorkflowRunHelper$ChangeMigrator.shouldSkipChange(WorkflowRunHelper.java:339)
        at com.google.copybara.WorkflowRunHelper$ChangeMigrator.skipChange(WorkflowRunHelper.java:317)
        at com.google.copybara.WorkflowMode.lambda$filterChanges$1(WorkflowMode.java:502)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1006)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
        at com.google.copybara.WorkflowMode.filterChanges(WorkflowMode.java:503)
        at com.google.copybara.WorkflowMode$1.run(WorkflowMode.java:110)
        at com.google.copybara.Workflow.run(Workflow.java:288)
        at com.google.copybara.MigrateCmd.run(MigrateCmd.java:92)
        at com.google.copybara.MigrateCmd.run(MigrateCmd.java:69)
        at com.google.copybara.Main.runInternal(Main.java:242)
        at com.google.copybara.Main.run(Main.java:124)
        at com.google.copybara.Main.main(Main.java:103)
ERROR: Unexpected error (please file a bug against copybara): Illegal char <<> at index 11: /file with <>.txt (java.nio.file.InvalidPathException: Illegal char <<> at index 11: /file with <>.txt)

I found this while trying to copybara the TypeScript repo. I found the issue on Windows, not sure if it repros on other platforms. Probably not since they probably don't use WindowsPathParser.

I worked around locally by catching the error in WorkflowRunHelper.java:317:

// From:
      for (String changedFile : currentChange.getChangeFiles()) {
        if (pathMatcher.matches(Paths.get("/" + changedFile))) {
          return false;
        }
      }
// To:
      for (String changedFile : currentChange.getChangeFiles()) {
        // `changedFile` might not be a valid path on some platforms.
        try {
          if (pathMatcher.matches(Paths.get("/" + changedFile))) {
            return false;
          }
        } catch (InvalidPathException e) {
          workflow.getConsole().warn("Couldn't parse path for file: " + changedFile);
        }
      }

Worked in my case, but probably not a good fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant