mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 03:49:44 -04:00
Revert 5eee555 and fix test
This commit is contained in:
parent
dc16fee8a0
commit
5dd3323782
@ -1288,30 +1288,24 @@ int metadata_<LoggerPolicy>::access(inode_view iv, int mode, uid_t uid,
|
||||
int access_mode = 0;
|
||||
int e_mode = iv.mode();
|
||||
|
||||
auto test = [this, e_mode, &access_mode](uint16_t r_bit, uint16_t w_bit,
|
||||
uint16_t x_bit) {
|
||||
auto test = [e_mode, &access_mode](uint16_t r_bit, uint16_t x_bit) {
|
||||
if (e_mode & r_bit) {
|
||||
access_mode |= R_OK;
|
||||
}
|
||||
if (e_mode & w_bit) {
|
||||
if (!options_.readonly) {
|
||||
access_mode |= W_OK;
|
||||
}
|
||||
}
|
||||
if (e_mode & x_bit) {
|
||||
access_mode |= X_OK;
|
||||
}
|
||||
};
|
||||
|
||||
// Let's build the inode's access mask
|
||||
test(S_IROTH, S_IWOTH, S_IXOTH);
|
||||
test(S_IROTH, S_IXOTH);
|
||||
|
||||
if (iv.getgid() == gid) {
|
||||
test(S_IRGRP, S_IWGRP, S_IXGRP);
|
||||
test(S_IRGRP, S_IXGRP);
|
||||
}
|
||||
|
||||
if (iv.getuid() == uid) {
|
||||
test(S_IRUSR, S_IWUSR, S_IXUSR);
|
||||
test(S_IRUSR, S_IXUSR);
|
||||
}
|
||||
|
||||
return (access_mode & mode) == mode ? 0 : EACCES;
|
||||
|
@ -37,6 +37,8 @@
|
||||
#include <folly/Subprocess.h>
|
||||
#include <folly/experimental/TestUtil.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "test_helpers.h"
|
||||
|
||||
namespace {
|
||||
@ -176,8 +178,26 @@ bool wait_until_file_ready(std::filesystem::path const& path,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_writable(std::filesystem::path const& p) {
|
||||
return ::access(p.c_str(), W_OK) == 0;
|
||||
bool check_readonly(std::filesystem::path const& p, bool readonly = false) {
|
||||
struct ::stat buf;
|
||||
if (::stat(p.c_str(), &buf) != 0) {
|
||||
throw std::runtime_error("could not stat " + p.string());
|
||||
}
|
||||
|
||||
bool is_writable = (buf.st_mode & S_IWUSR) != 0;
|
||||
|
||||
if (is_writable == readonly) {
|
||||
std::cerr << "readonly=" << readonly << ", st_mode=" << fmt::format("{0:o}", buf.st_mode) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (::access(p.c_str(), W_OK) == 0) {
|
||||
// access(W_OK) should never succeed
|
||||
::perror("access");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
::nlink_t num_hardlinks(std::filesystem::path const& p) {
|
||||
@ -240,7 +260,7 @@ TEST(tools, everything) {
|
||||
ASSERT_TRUE(check_run(diff_bin, "-qruN", data_dir, mountpoint));
|
||||
|
||||
EXPECT_EQ(1, num_hardlinks(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(is_writable(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(check_readonly(mountpoint / "format.sh"));
|
||||
}
|
||||
|
||||
{
|
||||
@ -249,7 +269,7 @@ TEST(tools, everything) {
|
||||
ASSERT_TRUE(check_run(diff_bin, "-qruN", data_dir, mountpoint));
|
||||
|
||||
EXPECT_EQ(3, num_hardlinks(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(is_writable(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(check_readonly(mountpoint / "format.sh"));
|
||||
}
|
||||
|
||||
{
|
||||
@ -259,7 +279,7 @@ TEST(tools, everything) {
|
||||
ASSERT_TRUE(check_run(diff_bin, "-qruN", data_dir, mountpoint));
|
||||
|
||||
EXPECT_EQ(3, num_hardlinks(mountpoint / "format.sh"));
|
||||
EXPECT_FALSE(is_writable(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(check_readonly(mountpoint / "format.sh", true));
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(fuse2_bin)) {
|
||||
@ -268,7 +288,7 @@ TEST(tools, everything) {
|
||||
ASSERT_TRUE(check_run(diff_bin, "-qruN", data_dir, mountpoint));
|
||||
|
||||
EXPECT_EQ(1, num_hardlinks(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(is_writable(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(check_readonly(mountpoint / "format.sh"));
|
||||
}
|
||||
|
||||
{
|
||||
@ -289,7 +309,7 @@ TEST(tools, everything) {
|
||||
ASSERT_TRUE(check_run(diff_bin, "-qruN", data_dir, mountpoint));
|
||||
|
||||
EXPECT_EQ(3, num_hardlinks(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(is_writable(mountpoint / "format.sh"));
|
||||
EXPECT_TRUE(check_readonly(mountpoint / "format.sh"));
|
||||
}
|
||||
|
||||
auto meta_export = td / "test.meta";
|
||||
|
Loading…
x
Reference in New Issue
Block a user