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 get_canonical/absolute/normalize_path() functions #100

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

dacap
Copy link
Member

@dacap dacap commented Jul 3, 2024

Several refactors in this commit:

  • Moved is_path_separator() function and path_separator as a constexpr to the header file
  • Added path_separators string (for Windows, which includes \ and /)
  • get_canonical_path() works only when the file exists (returns an empty string in other case)
  • normalize_path() and get_absolute_path() work in a lexical level, handling only strings and getting the current path when needed, but without checking the existence of the file

Fix #98

@dacap dacap self-assigned this Jul 3, 2024
aseprite-bot

This comment was marked as resolved.

@dacap dacap force-pushed the paths branch 2 times, most recently from e965896 to c0793a9 Compare July 3, 2024 17:57
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

base/fs_unix.h Outdated
@@ -208,11 +209,24 @@ std::string get_user_docs_folder()

std::string get_canonical_path(const std::string& path)
{
std::string full = get_absolute_path(path);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'full' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string full = get_absolute_path(path);
std::string const full = get_absolute_path(path);

return std::string();
}

std::string get_absolute_path(const std::string& path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: function 'get_absolute_path' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]

std::string get_absolute_path(const std::string& path)
            ^
Additional context

base/fs_unix.h:220: make as 'inline'

std::string get_absolute_path(const std::string& path)
            ^

const std::string full = get_absolute_path(path);
DWORD attr = ::GetFileAttributes(from_utf8(full).c_str());
if (attr != INVALID_FILE_ATTRIBUTES)
return full;
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: constness of 'full' prevents automatic move [performance-no-automatic-move]

    return full;
           ^

Several refactors in this commit:

- Moved is_path_separator() function and path_separator as a constexpr
  to the header file
- Added path_separators string (for Windows, which includes \ and /)
- get_canonical_path() works only when the file exists (returns an
  empty string in other case)
- normalize_path() and get_absolute_path() work in a lexical level,
  handling only strings and getting the current path when needed, but
  without checking the existence of the file
@dacap dacap merged commit 2a25a91 into aseprite:main Jul 4, 2024
8 checks passed
@dacap dacap deleted the paths branch July 4, 2024 00:01
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.

Fix get_canonical_path and get_absolute_path behavior
2 participants