-
Notifications
You must be signed in to change notification settings - Fork 341
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
Filesystem library #2879
Filesystem library #2879
Conversation
libmamba/src/filesystem/u8path.cpp
Outdated
static constexpr wchar_t platform_separator = L'\\'; | ||
static constexpr wchar_t other_separator = L'/'; | ||
|
||
auto pos = native_string.find(other_separator); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was util::replace_all
not good enough here? Also I would prefer this loop to be a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I am trying to get to a state of multiple internal "libraries" where there is no cyclic dependencies between them.
The goal is to restrict what code can be used where, so that for instance "filesystem" or "util" does not start calling code form "core". These restrictions would then restrict the opportunities for spaghetti code.
Or maybe I am being too dogmatic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine but it's not clear to me how this is related to this code, is it because otherwise there is a cyclic dependency between the filesystem and utils? If so, maybe isolating that specific replace function in it's header would solve the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Klaim I wanted to use CMake add_library(mamba-fs OBJECT filesystem.cpp)
to literally forbid including code from the rest of mamba in this library (and then do the same with mamba-util
, mamba-solv-cpp
...).
With more investigation, it turns out it's not so easy to do: since the headers are public, they still need to be added to libmamba to be installed, so I'm not sure it's worth the trouble.
For this particular issue, it turns out that since L"\\"
and L"/"
are in fact single characters, a simple call to std::replace
will do (and is probably more performant). What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see, following your intention would also mean splitting utility in small libraries and making the filesystem library only depend on what it needs in the utility libraries. Note that, it can be done but then these libraries needs to not be distributed separately but only be an implementation detail, linked statically into libmamba. If they are public, then yep we either have to distribute them on the side of libmamba or not make it a library, same conclusion as yours.
For std::replace
I would agree in general but I didnt check if it's strictly equivalent to what the utility function was doing? Or said another way: do you see why the function was initially created? What's the difference with std::replace
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway if it's tested and std::replace
works in that specific function, I'm fine by it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
std::replace
I would agree in general but I didnt check if it's strictly equivalent to what the utility function was doing? Or said another way: do you see why the function was initially created? What's the difference withstd::replace
?
@Klaim util::replace_all
works with string_view
. It will look for substrings, and replace with another string, moving all characters:
util::replace_all("ab_ab", "ab", "hello"); # "hello_hello"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK then I guess we can use replace
94abf13
to
7e6cd56
Compare
@@ -17,11 +16,12 @@ | |||
#include "mamba/core/context.hpp" | |||
#include "mamba/core/download.hpp" | |||
#include "mamba/core/error_handling.hpp" | |||
#include "mamba/core/mamba_fs.hpp" | |||
#include "mamba/core/fetch.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: subdirdata has been refactored and does not depend anymore on this file, so we should not include it. This can be removed later, when fetch.hpp
is removed from the code base.
#ifndef MAMBA_CORE_FS_HPP | ||
#define MAMBA_CORE_FS_HPP | ||
#ifndef MAMBA_CORE_FS_FILESYSTEM_HPP | ||
#define MAMBA_CORE_FS_FILESYSTEM_HPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking: should the inclusion guard be MAMBA_FS_FILESYSTEM
? As for previous comment, this can be done in a further PR, to avoid conflicts if we are slow to merge this.
No description provided.