Skip to content

Commit

Permalink
Add error handling and fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa committed Dec 1, 2022
1 parent 9486aa5 commit db76640
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions libmamba/include/mamba/core/mamba_fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "mamba/core/util_string.hpp"

#if ! defined(_WIN32)
#include <sys/stat.h>
#include <fcntl.h>
#if !defined(_WIN32)
#include <sys/stat.h>
#include <fcntl.h>
#endif


Expand Down Expand Up @@ -69,8 +69,10 @@

namespace fs
{
// use named class as sentinel argument for last_write_time
class now {};
// sentinel argument for indicating the current time to last_write_time
class now
{
};


#if defined(_WIN32)
Expand Down Expand Up @@ -1156,21 +1158,31 @@ namespace fs
return std::filesystem::last_write_time(path, std::forward<OtherArgs>(args)...);
}

// void last_write_time(const path& p, file_time_type new_time);
// void last_write_time(const path& p, file_time_type new_time, error_code& ec) noexcept;
template <typename... OtherArgs>
void last_write_time(const u8path& path, now _, OtherArgs&&... args)
// void last_write_time(const path& p, now _, error_code& ec) noexcept;
inline void last_write_time(const u8path& path, now _, std::error_code& ec) noexcept
{
#if defined(_WIN32)
auto new_time = fs::file_time_type::clock::now();
return std::filesystem::last_write_time(path, new_time, std::forward<OtherArgs>(args)...);
return std::filesystem::last_write_time(path, new_time, ec);
#else
int err = utimensat(AT_FDCWD, path.string().c_str(), NULL, AT_SYMLINK_NOFOLLOW);
if (err == 0) return;
// TODO proper err handling
if (utimensat(AT_FDCWD, path.string().c_str(), NULL, 0) == -1)
{
ec = std::error_code(errno, std::generic_category());
}
#endif
}

// void last_write_time(const path& p, now _);
inline void last_write_time(const u8path& path, now sentinel)
{
std::error_code ec;
last_write_time(path, sentinel, ec);
if (ec)
{
throw filesystem_error("last_write_time", path, ec);
}
}

// void last_write_time(const path& p, file_time_type new_time);
// void last_write_time(const path& p, file_time_type new_time, error_code& ec) noexcept;
template <typename... OtherArgs>
Expand Down

0 comments on commit db76640

Please sign in to comment.