This commit is contained in:
parent
84fc05acc0
commit
18c53fad9a
@ -218,8 +218,8 @@ public:
|
||||
}
|
||||
|
||||
static void unlink_root_file(const std::string &file_path) {
|
||||
auto api_path =
|
||||
utils::path::create_api_path(utils::path::strip_to_filename(file_path));
|
||||
auto api_path = utils::path::create_api_path(
|
||||
utils::path::strip_to_file_name(file_path));
|
||||
|
||||
provider->set_item_meta(api_path, {
|
||||
{META_UID, std::to_string(getuid())},
|
||||
|
@ -20,6 +20,7 @@
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if !defined(_WIN32)
|
||||
#if 0
|
||||
|
||||
#include "fixtures/fuse_fixture.hpp"
|
||||
|
||||
@ -646,4 +647,5 @@ TYPED_TEST(fuse_test, can_not_chown_user_if_not_root) {
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // 0
|
||||
#endif // !defined(_WIN32)
|
||||
|
@ -48,8 +48,6 @@ public:
|
||||
std::unique_ptr<wd_t> where_data;
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
||||
public:
|
||||
db_delete(sqlite3 &db3, std::string table_name)
|
||||
: ctx_(std::make_shared<context>(&db3, table_name)) {}
|
||||
@ -64,8 +62,8 @@ public:
|
||||
|
||||
[[nodiscard]] auto go() const -> db_result;
|
||||
|
||||
[[nodiscard]] auto group(context::w_t::group_func_t func)
|
||||
-> context::w_t::wn_t;
|
||||
[[nodiscard]] auto
|
||||
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
|
||||
|
||||
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
||||
};
|
||||
|
@ -45,7 +45,6 @@ public:
|
||||
|
||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
|
||||
|
||||
|
||||
-> db_update_op_t;
|
||||
};
|
||||
|
||||
@ -57,11 +56,8 @@ public:
|
||||
std::optional<std::pair<std::string, bool>> order_by;
|
||||
|
||||
std::unique_ptr<wd_t> where_data;
|
||||
clear();
|
||||
};
|
||||
|
||||
using row = db_row<context>;
|
||||
|
||||
public:
|
||||
db_update(sqlite3 &db3, std::string table_name)
|
||||
: ctx_(std::make_shared<context>(&db3, table_name)) {}
|
||||
@ -74,7 +70,6 @@ private:
|
||||
public:
|
||||
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
|
||||
|
||||
|
||||
-> db_update &;
|
||||
|
||||
[[nodiscard]] auto dump() const -> std::string;
|
||||
@ -83,14 +78,12 @@ public:
|
||||
|
||||
[[nodiscard]] auto group(context::w_t::group_func_t func)
|
||||
|
||||
|
||||
-> context::w_t::wn_t;
|
||||
|
||||
[[nodiscard]] auto limit(std::int32_t value) -> db_update &;
|
||||
|
||||
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
|
||||
|
||||
|
||||
-> db_update &;
|
||||
|
||||
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include "utils/db/sqlite/db_insert.hpp"
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
auto db_insert::column_value(std::string column_name, db_types_t value)
|
||||
-> db_insert & {
|
||||
auto db_insert::column_value(std::string column_name,
|
||||
db_types_t value) -> db_insert & {
|
||||
ctx_->values[column_name] = value;
|
||||
return *this;
|
||||
}
|
||||
@ -71,17 +71,17 @@ auto db_insert::go() const -> db_result {
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(ctx_->values.size()); idx++) {
|
||||
res = std::visit(overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1,
|
||||
data);
|
||||
},
|
||||
[this, &idx](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1,
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
std::next(ctx_->values.begin(), idx)->second);
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[&idx, &stmt_ptr](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
|
||||
},
|
||||
[&idx, &stmt_ptr](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
|
||||
nullptr);
|
||||
},
|
||||
},
|
||||
std::next(ctx_->values.begin(), idx)->second);
|
||||
if (res != SQLITE_OK) {
|
||||
return {stmt_ptr, res};
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ auto db_select::column(std::string column_name) -> db_select & {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::count(std::string column_name, std::string as_column_name)
|
||||
-> db_select & {
|
||||
auto db_select::count(std::string column_name,
|
||||
std::string as_column_name) -> db_select & {
|
||||
ctx_->count_columns[column_name] = as_column_name;
|
||||
return *this;
|
||||
}
|
||||
@ -151,12 +151,12 @@ auto db_select::go() const -> db_result {
|
||||
idx++) {
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1, data);
|
||||
[&idx, &stmt_ptr](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
|
||||
},
|
||||
[this, &idx](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1, data.c_str(),
|
||||
-1, nullptr);
|
||||
[&idx, &stmt_ptr](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
|
||||
nullptr);
|
||||
},
|
||||
},
|
||||
ctx_->where_data->values.at(static_cast<std::size_t>(idx)));
|
||||
@ -195,8 +195,8 @@ auto db_select::offset(std::int32_t value) -> db_select & {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_select::order_by(std::string column_name, bool ascending)
|
||||
-> db_select & {
|
||||
auto db_select::order_by(std::string column_name,
|
||||
bool ascending) -> db_select & {
|
||||
ctx_->order_by = {column_name, ascending};
|
||||
return *this;
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ auto db_update::context::db_update_op_t::order_by(std::string column_name,
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::column_value(std::string column_name, db_types_t value)
|
||||
-> db_update & {
|
||||
auto db_update::column_value(std::string column_name,
|
||||
db_types_t value) -> db_update & {
|
||||
ctx_->column_values[column_name] = value;
|
||||
return *this;
|
||||
}
|
||||
@ -97,17 +97,17 @@ auto db_update::go() const -> db_result {
|
||||
|
||||
for (std::int32_t idx = 0;
|
||||
idx < static_cast<std::int32_t>(ctx_->column_values.size()); idx++) {
|
||||
res = std::visit(overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(ctx_->stmt.get(), idx + 1,
|
||||
data);
|
||||
},
|
||||
[this, &idx](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(ctx_->stmt.get(), idx + 1,
|
||||
data.c_str(), -1, nullptr);
|
||||
},
|
||||
},
|
||||
std::next(ctx_->column_values.begin(), idx)->second);
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[&stmt_ptr, &idx](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(stmt_ptr, idx + 1, data);
|
||||
},
|
||||
[&stmt_ptr, &idx](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(stmt_ptr, idx + 1, data.c_str(), -1,
|
||||
nullptr);
|
||||
},
|
||||
},
|
||||
std::next(ctx_->column_values.begin(), idx)->second);
|
||||
if (res != SQLITE_OK) {
|
||||
return {stmt_ptr, res};
|
||||
}
|
||||
@ -122,16 +122,16 @@ auto db_update::go() const -> db_result {
|
||||
idx++) {
|
||||
res = std::visit(
|
||||
overloaded{
|
||||
[this, &idx](std::int64_t data) -> std::int32_t {
|
||||
[this, &idx, &stmt_ptr](std::int64_t data) -> std::int32_t {
|
||||
return sqlite3_bind_int64(
|
||||
ctx_->stmt.get(),
|
||||
stmt_ptr,
|
||||
idx + static_cast<std::int32_t>(ctx_->column_values.size()) +
|
||||
1,
|
||||
data);
|
||||
},
|
||||
[this, &idx](const std::string &data) -> std::int32_t {
|
||||
[this, &idx, &stmt_ptr](const std::string &data) -> std::int32_t {
|
||||
return sqlite3_bind_text(
|
||||
ctx_->stmt.get(),
|
||||
stmt_ptr,
|
||||
idx + static_cast<std::int32_t>(ctx_->column_values.size()) +
|
||||
1,
|
||||
data.c_str(), -1, nullptr);
|
||||
@ -163,8 +163,8 @@ auto db_update::limit(std::int32_t value) -> db_update & {
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto db_update::order_by(std::string column_name, bool ascending)
|
||||
-> db_update & {
|
||||
auto db_update::order_by(std::string column_name,
|
||||
bool ascending) -> db_update & {
|
||||
ctx_->order_by = {column_name, ascending};
|
||||
return *this;
|
||||
}
|
||||
|
@ -19,10 +19,11 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include <utils/config.hpp>
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "utils/unix.hpp"
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/unix.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
#if !defined(__APPLE__)
|
||||
@ -39,7 +40,7 @@ auto get_thread_id() -> std::uint64_t {
|
||||
|
||||
auto is_uid_member_of_group(const uid_t &uid, const gid_t &gid) -> bool {
|
||||
std::vector<gid_t> groups{};
|
||||
use_getpwuid(uid, [&groups](struct passwd *pass) {
|
||||
auto res = use_getpwuid(uid, [&groups](struct passwd *pass) {
|
||||
int group_count{};
|
||||
if (getgrouplist(pass->pw_name, pass->pw_gid, nullptr, &group_count) < 0) {
|
||||
groups.resize(static_cast<std::size_t>(group_count));
|
||||
@ -52,6 +53,11 @@ auto is_uid_member_of_group(const uid_t &uid, const gid_t &gid) -> bool {
|
||||
}
|
||||
});
|
||||
|
||||
if (not res.ok) {
|
||||
throw utils::error::create_exception(res.function_name,
|
||||
{"use_getpwuid failed", res.reason});
|
||||
}
|
||||
|
||||
return collection::includes(groups, gid);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user