Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Conversation

@peterflynn
Copy link
Member

The "canonical" folder path format used in DirectoryEntry.fullPath includes a trailing "/". However, we have some Brackets code that requires or generates paths in the opposite format. This cleans up several of those cases:

  • Rename FileUtils.canonicalizeFolderPath() to stripTrailingSlash() since it actually makes paths NOT canonical. Old API is deprecated but left in place for now (it's used by several extensions -- I'll file bugs once this lands).
  • Add warning to docs for two other APIs that return non-canonical paths: FileUtils.getNativeBracketsDirectoryPath() & FileUtils.getNativeModuleDirectoryPath()
  • Indicate explicitly that ProjectManager._loadProject() / openProject() support receiving non-canonical paths
  • Fix several ProjectManager APIs that used to return and/or receive non-canonical paths -- getInitialProjectPath(), _getWelcomeProjectPath(), updateWelcomeProjectPath(). No extensions use these APIs.
  • Centralize code that touches "welcomeProjects" pref storage, for clarity

This is an incremental improvement. Not everything has been cleaned up:

  • Some code still calls openProject() with non-canonical paths
  • RecentProjects still works with non-canonical paths internally (including its pref storage)
  • The list of previous "welcomeProjects" is still stored non-canonicalized
  • ScopeManager (in JS code hints) still requires non-canonical paths in some places (while requiring canonical paths in others! 😂)
  • The two getNative*() APIs above still return non-canonical paths -- though I think we can fix these soon. It will be safer to change these once we have the new filesystem because it's more careful about handling duplicated slashes.

- Rename FileUtils.canonicalizeFolderPath() to stripTrailingSlash() since
it actually makes paths NOT canonical. Old API left in place with
deprecation warning for now.
- Add warning to docs for a few other APIs that return non-canonical paths:
FileUtils.getNativeBracketsDirectoryPath(), FileUtils.getNativeModuleDirectoryPath(),
ProjectManager.getInitialProjectPath(), ProjectManager.updateWelcomeProjectPath()
ProjectManager._getWelcomeProjectPath()
- Indicate explicitly which ProjectManager APIs support receiving
non-canonical paths
- Centralize code that touches welcomeProjects storage pref for clarity

What this does NOT do:
- Fix the other APIs listed above that still return non-canonical paths
- Fix non-canonical first-launch project path given to _loadProject()
- Fix non-canonical paths used in RecentProjects prefs
- Fix non-canonical paths used in welcomeProjects pref
- Fix ScopeManager, which in some places requires canonical paths and
in other places requires non-canonical paths
… non-

canonical:
- ProjectManager.getInitialProjectPath() - always returns canonical
- ProjectManager._getWelcomeProjectPath() - always returns canonical
- ProjectManager.updateWelcomeProjectPath() - arg assumed to be canonical &
always returns canonical

None of these APIs are used in extensions.

This does NOT change the underlying "welcomeProjects" pref - like
"recentProjects", it still stores paths without trailing "/" under the hood
@peterflynn
Copy link
Member Author

@njx You might want to look at this if you have time, since it largely concerns the "welcome project" detection and the RecentProjects extension -- both of which I think you've worked on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to check the length here? Seems that we should make sure it isn't an empty string and is truthy before invoking the index operator.

Copy link
Member Author

Choose a reason for hiding this comment

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

Arrays in JS aren't length checked -- you just get undefined for outside of range indices. So the equality check is guaranteed to correctly evaluate to false for an empty string.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll re-add it though just so it's more explicit

@JeffryBooher
Copy link
Contributor

Done with initial review. just a few minor nits.

@peterflynn
Copy link
Member Author

@JeffryBooher Changes pushed -- let me know if you need me to address anything else

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why this isn't a public function in FileUtils.js? Seems handy to have for other modules/extensions to be able to use

Copy link
Member Author

Choose a reason for hiding this comment

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

@JeffryBooher I'm hoping we won't need to get people in the habit of manually normalizing paths. Even in Brackets today, folder paths from almost every API are guaranteed to end in "/" -- these ones ProjectManager deals with are among the few exceptions. And the newer file API we're working on will make that guarantee even more explicit.

@JeffryBooher
Copy link
Contributor

Looks good. Unit/Integration tests pass. Merging

JeffryBooher added a commit that referenced this pull request Oct 22, 2013
Better compartmentalize code that assumes no trailing "/"
@JeffryBooher JeffryBooher merged commit 8ca47a5 into master Oct 22, 2013
@JeffryBooher JeffryBooher deleted the pflynn/trailing-slash-cleanup branch October 22, 2013 17:17
@peterflynn
Copy link
Member Author

Thanks @JeffryBooher!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants