-
Notifications
You must be signed in to change notification settings - Fork 3
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
WIP: Repository class refactoring #95
base: master
Are you sure you want to change the base?
Changes from 2 commits
a01df8c
6fe6003
99f79ce
3f0f219
37f8b60
ab4ba11
25df8ed
de966e5
4895e2e
a834f94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,65 +58,64 @@ class repository_exception : public std::runtime_error { | |
} | ||
}; | ||
|
||
|
||
|
||
/** | ||
* Generic file class | ||
* | ||
* This class should only read and write, | ||
* This class should only read and write, | ||
*/ | ||
class GenericFile { | ||
protected: | ||
std::filesystem::path m_path; | ||
|
||
public: | ||
GenericFile(const std::filesystem::path& path) | ||
: m_path(path) | ||
{} | ||
{ | ||
} | ||
|
||
virtual void read() {} | ||
virtual void write() {} | ||
virtual void read() { } | ||
virtual void write() { } | ||
}; | ||
|
||
|
||
|
||
struct ELRepo { | ||
dhilst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::string group; | ||
std::string name; | ||
std::optional<std::string> baseURL; | ||
std::optional<std::string> base_url; | ||
std::optional<std::string> metalink; | ||
bool enabled; | ||
bool gpgcheck; | ||
std::string gpgkey; | ||
|
||
// (P/ todos os repositórios) | ||
// std::string release; | ||
|
||
}; | ||
|
||
|
||
/** | ||
* Repository file class | ||
* | ||
* This class should parse the repository data | ||
*/ | ||
class ELRepoFile : GenericFile { | ||
private: | ||
private: | ||
Glib::RefPtr<Glib::KeyFile> m_file; | ||
|
||
std::vector<ELRepo> parseData(); | ||
void unparseData(const std::vector<ELRepo>&); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing the variable name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable name is not needed in the declaration and the context is obvious, but I will fixed because of conventions |
||
|
||
public: | ||
ELRepoFile(const std::filesystem::path& path) | ||
: GenericFile(path) | ||
{} | ||
{ | ||
} | ||
|
||
virtual void read() override; | ||
virtual void write() override; | ||
|
||
std::vector<ELRepo> parse(); | ||
std::vector<ELRepo> parse(const std::stringstream& ss); | ||
void unparse( const std::vector<ELRepo>& repositories ); | ||
void unparse( const std::vector<ELRepo>& repositories, std::stringstream& ss ); | ||
void unparse(const std::vector<ELRepo>& repositories); | ||
void unparse( | ||
const std::vector<ELRepo>& repositories, std::stringstream& ss); | ||
}; | ||
|
||
#endif // CLOYSTERHPC_REPO_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,4 +351,12 @@ void copyFile(std::filesystem::path source, std::filesystem::path destination) | |
} | ||
} | ||
|
||
std::optional<Glib::ustring> readKeyfileString(Glib::RefPtr<Glib::KeyFile> file, | ||
const std::string_view& group, const std::string_view& key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to be const ref. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See this comment |
||
{ | ||
return file->has_key(group.data(), key.data()) | ||
? std::make_optional(file->get_string(group.data(), key.data())) | ||
: std::nullopt; | ||
} | ||
|
||
} // namespace cloyster |
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.
std:string_view
is already a pointer to a string. It should not be passed as const ref.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.
I didn't know that. I thought it was pointer+length. It will be fixed