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

fix(cli): handle patterns correctly on Windows #10430

Merged
merged 1 commit into from
Jun 22, 2024

Conversation

fky2015
Copy link
Contributor

@fky2015 fky2015 commented Jun 17, 2024

fast-glob requires slash (instead of backslash) for matching path.

So before this change, --recursive didn't work on WIndows.

Before:
image

After:
image

Some changes

  • On Windows, use convertPathToPattern from fast-glob.
  • Add test CI for CLI on the Windows platform.
  • To unify the test cases (a file may have multiple valid path formats), compare file contents instead of the paths.

@github-actions github-actions bot added the cli Tasks related to the Immich CLI label Jun 17, 2024
@alextran1502 alextran1502 enabled auto-merge (squash) June 17, 2024 15:34
@alextran1502 alextran1502 disabled auto-merge June 17, 2024 15:38
@alextran1502
Copy link
Contributor

Can you please update the unit test as well?

@fky2015
Copy link
Contributor Author

fky2015 commented Jun 17, 2024

Sure, I'm working on that.

@fky2015 fky2015 marked this pull request as draft June 17, 2024 18:34
@fky2015 fky2015 force-pushed the main branch 3 times, most recently from 2e88a70 to ae4cb06 Compare June 18, 2024 12:25
@fky2015 fky2015 marked this pull request as ready for review June 18, 2024 12:35
@fky2015 fky2015 requested a review from bo0tzz as a code owner June 18, 2024 12:35
@fky2015 fky2015 changed the title feat(cli): handle patterns correctly on Windows fix(cli): handle patterns correctly on Windows Jun 19, 2024
@fky2015 fky2015 closed this Jun 19, 2024
Modify the handling of patterns in the `crawl` function to correctly
convert the current path to a pattern when it contains backslash on
Windows, in according to fast-glob's docs.
@fky2015 fky2015 reopened this Jun 19, 2024
@fky2015
Copy link
Contributor Author

fky2015 commented Jun 19, 2024

@bo0tzz Can you review this PR for me? Thanks!

Comment on lines +111 to +113
const convertPathToPatternOnWin = (path: string) => {
return platform() === 'win32' ? convertPathToPattern(path) : path;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be conditional to the platform, would there be any issues with just always converting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, convertPathToPattern will change the matching behavior on *nix platform:

/photo* will become /photo\* thus the asterisk will lose its effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't change the behaviour on windows? If so that sounds weird, do you know why it is like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't change the behaviour on Windows.

From my understanding, convertPathToPattern is a function especially used for converting a Windows path to fast-glob search pattern. It is meaningless to use this function if your inputs are a valid POSIX path.

@@ -2,6 +2,7 @@ import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
resolve: { alias: { src: '/src' } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

@fky2015 fky2015 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed cli/README.md and filed to build the project without this change to the config (on Windows).

error during build:
[vite]: Rollup failed to resolve import "src/commands/asset" from "D:\code\immich\cli\src\index.ts".

image

Generally speaking, I think this change will improve the compatibility of dev configs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a few changes in this test that look odd to me, can you explain what's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #265: On the Windows platform, / cannot be treated as expected in fast-glob. I've filed an issue here mrmlnc/fast-glob#447.

Line #286 & #294: Comparing path strings directly will lead to some false positive cases. For example, on Windows, a path can be written as D:\Something\Like\This while \something\like\this on Linux. So It should be better to compare what they've actually read in the file system. To achieve this, I'm letting each file contain unique contents (their paths) so that it can be used for comparison later. A good thing to note is that we are still comparing their paths and this is friendly when debugging.

@bo0tzz bo0tzz requested a review from jrasm91 June 19, 2024 16:43
@alextran1502 alextran1502 merged commit 4cb1653 into immich-app:main Jun 22, 2024
28 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Tasks related to the Immich CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants