Commit bbbf361f authored by Pádraig Ó Conbhuí's avatar Pádraig Ó Conbhuí
Browse files

Fixed missing quiet flang in format.sh. Formatted and linted project.

parent 047f4c2e
#include <megadep/common_types.hpp> #include <megadep/common_types.hpp>
#include <megadep/megadep.hpp> #include <megadep/megadep.hpp>
#include <cerrno>
#include <cstring> #include <cstring>
#include <dirent.h> #include <dirent.h>
namespace megadep { namespace megadep {
std::vector<FileName> list_files(const DirectoryName &directory) { std::vector<FileName> list_files(const DirectoryName &directory) {
namespace fs = std::filesystem;
std::vector<FileName> file_names; std::vector<FileName> file_names;
DIR *dir_ptr; DIR *dir_ptr;
...@@ -17,7 +16,7 @@ std::vector<FileName> list_files(const DirectoryName &directory) { ...@@ -17,7 +16,7 @@ std::vector<FileName> list_files(const DirectoryName &directory) {
dir_ptr = opendir(directory.c_str()); dir_ptr = opendir(directory.c_str());
// Directory is a file, return the directory name // Directory is a file, return the directory name
if (dir_ptr == NULL) { if (dir_ptr == nullptr) {
if (errno == ENOTDIR || errno == ENOENT) { if (errno == ENOTDIR || errno == ENOENT) {
return {directory}; return {directory};
} }
...@@ -25,17 +24,19 @@ std::vector<FileName> list_files(const DirectoryName &directory) { ...@@ -25,17 +24,19 @@ std::vector<FileName> list_files(const DirectoryName &directory) {
return {}; return {};
} }
while (entity_ptr = readdir(dir_ptr)) { while ((entity_ptr = readdir(dir_ptr)) != nullptr) {
const char *entity_name = entity_ptr->d_name; const char *entity_name = static_cast<const char *>(entity_ptr->d_name);
// Skip . and .. // Skip . and ..
if (strcmp(entity_name, ".") == 0) if (strcmp(entity_name, ".") == 0) {
continue; continue;
if (strcmp(entity_name, "..") == 0) }
if (strcmp(entity_name, "..") == 0) {
continue; continue;
}
// Try recursing // Try recursing
auto sub_files = list_files(directory + '/' + entity_ptr->d_name); auto sub_files = list_files(directory + '/' + entity_name);
for (auto &sub_file : sub_files) { for (auto &sub_file : sub_files) {
file_names.emplace_back(std::move(sub_file)); file_names.emplace_back(std::move(sub_file));
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
namespace megadep { namespace megadep {
std::vector<FileName> list_files(const DirectoryName &directories); std::vector<FileName> list_files(const DirectoryName &directory);
} } // namespace megadep
#endif // MEGADEP_MEGADEP_HPP #endif // MEGADEP_MEGADEP_HPP
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
#include <megadep/megadep.hpp> #include <megadep/megadep.hpp>
using namespace megadep;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto files = list_files(argv[1]); if (argc != 2) {
std::cout << "Must provide directory argument!\n";
return 1;
}
auto files = megadep::list_files(argv[1]); // NOLINT
for (const auto &file : files) { for (const auto &file : files) {
std::cout << file << '\n'; std::cout << file << '\n';
} }
......
...@@ -107,7 +107,7 @@ then ...@@ -107,7 +107,7 @@ then
# If the formatted and unformatted files are the same, don't # If the formatted and unformatted files are the same, don't
# touch the original # touch the original
if ! cmp "${tmpfile}" "${target_file}" if ! cmp --quiet "${tmpfile}" "${target_file}"
then then
# Using cat instead of mv to preserve permissions etc. # Using cat instead of mv to preserve permissions etc.
cat "${tmpfile}" > "${target_file}" cat "${tmpfile}" > "${target_file}"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment