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: correct detection of obsolete files #776

Merged
merged 5 commits into from
May 9, 2024

Conversation

anbraten
Copy link
Contributor

@anbraten anbraten commented Apr 26, 2024

closes #775

Repro: https://github.com/anbraten/repro-crowdin-delete-obsolete

I am not sure why the exportPattern of a source-file was checked to see that it is obsolete. It works for me without the check, but I would also be happy to fix the check if it's needed and someone could explain me how it should work.

@anbraten anbraten changed the title Fix detecting of obsolete files fix: correct detection of obsolete files Apr 26, 2024
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 63.78%. Comparing base (2d4d0f0) to head (4578ccb).

Files Patch % Lines
...i/commands/functionality/ObsoleteSourcesUtils.java 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #776      +/-   ##
============================================
+ Coverage     63.73%   63.78%   +0.05%     
- Complexity     1504     1505       +1     
============================================
  Files           220      220              
  Lines          6294     6297       +3     
  Branches        944      944              
============================================
+ Hits           4011     4016       +5     
  Misses         1778     1778              
+ Partials        505      503       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrii-bodnar andrii-bodnar marked this pull request as draft May 2, 2024 08:44
@anbraten
Copy link
Contributor Author

anbraten commented May 7, 2024

Not sure where the windows issue was exactly coming from. Probably some path separator mismatch.

@anbraten anbraten marked this pull request as ready for review May 7, 2024 09:46
@andrii-bodnar
Copy link
Member

andrii-bodnar commented May 7, 2024

@anbraten yes, most likely it is related to paths. We already have some similar tests, and the easiest option here is to have separate test cases for Linux/Mac and Windows operating systems.

These tests have the following annotations:

@DisabledOnOs({OS.LINUX, OS.MAC})
@DisabledOnOs(OS.WINDOWS)

Or we can somehow normalize the paths to unify them for those environments.

@@ -29,7 +29,10 @@ public static Map<String, File> findObsoleteProjectFiles(

private static boolean checkExportPattern(String exportPattern, File file) {
String fileExportPattern = ProjectFilesUtils.getExportPattern(file.getExportOptions());
return exportPattern.equals(fileExportPattern != null ? Utils.normalizePath(fileExportPattern) : null);
if (fileExportPattern == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrii-bodnar What do you think of this approach?

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 mean that files with the null export pattern will be considered obsolete and deleted, or the opposite?

Copy link
Contributor Author

@anbraten anbraten May 8, 2024

Choose a reason for hiding this comment

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

It basically uses all projectFiles (files received by the api) and checks for each file:

  • if that file matches the config patterns (source-pattern, ignore and preserveHierarchy)
  • if it matches the exportPattern (if the api returns null for the export pattern we ignore it now by this change)
  • and if the file has isFileDontHaveUpdate=true (which seems to check if the file is not part of the local files anymore)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I adjusted some var and method names so they match the rest of the code and are hopefully more descriptive.

Copy link
Member

Choose a reason for hiding this comment

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

@anbraten great, I just tested it locally and the fix works for me, thank you! 🚀

@andrii-bodnar andrii-bodnar merged commit 94fb3bf into crowdin:main May 9, 2024
8 checks passed
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

Successfully merging this pull request may close these issues.

Detecting / deleting obsolete files not working
2 participants