清理旧数据操作无效问题修复

This commit is contained in:
shell committed 2026-07-31 07:18:23 +08:00
1 parent 7296b3096a
commit c451a077b2
7 files changed
+84 -48

No files matched your search

+2
View File
@@ -65,6 +65,8 @@ add_executable(seadisk src/main.cpp
include/seafile/fs/storage/repo_info.hpp
src/seafile/fs/storage/repo_info.cpp
include/seafile/fs/setting.hpp
src/seafile/fs/setting.cpp
include/seafile/literals/units.hpp
)
target_compile_definitions(seadisk PRIVATE
+5
View File
@@ -6,6 +6,7 @@
#define SEADISK_SETTING_HPP
#include <string>
#include <nlohmann/json.hpp>
#include <tl/expected.hpp>
namespace seafile::fs
{
@@ -18,6 +19,10 @@ namespace seafile::fs
std::string mount_label;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Setting, server, user, password, mount_point, mount_label);
static auto load(const std::string& path) -> tl::expected<Setting, std::exception>;
static auto load(const std::filesystem::path& path) -> tl::expected<Setting, std::exception>;
};
}
#endif //SEADISK_SETTING_HPP
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Shell on 2026/7/30.
//
#ifndef SEADISK_UNITS_HPP
#define SEADISK_UNITS_HPP
#include <cstddef>
namespace seafile::literals {
constexpr std::size_t operator"" _B(unsigned long long v) {
return v;
}
constexpr std::size_t operator"" _KB(unsigned long long v) {
return v * 1024ULL;
}
constexpr std::size_t operator"" _MB(unsigned long long v) {
return v * 1024ULL * 1024ULL;
}
constexpr std::size_t operator"" _GB(unsigned long long v) {
return v * 1024ULL * 1024ULL * 1024ULL;
}
}
#endif //SEADISK_UNITS_HPP
+2
View File
@@ -7,6 +7,8 @@
namespace seafile::fs
{
using RepoInfo = storage::RepoInfo;
using RepoEntry = storage::RepoEntry;
namespace
{
constexpr int64_t UNIX_EPOCH_AS_FILETIME = 116444736000000000LL;
+25
View File
@@ -0,0 +1,25 @@
//
// Created by Shell on 2026/7/30.
//
#include "seafile/fs/setting.hpp"
#include <fstream>
namespace seafile::fs {
auto Setting::load(const std::filesystem::path &path) -> tl::expected<Setting, std::exception> {
try{
const auto size = std::filesystem::file_size(path);
std::string data(size, '\0');
std::ifstream file(path, std::ios::binary);
file.read(data.data(), size);
return nlohmann::json::parse(data).get<Setting>();
}
catch (const std::exception& ex)
{
return tl::make_unexpected(ex);
}
}
auto Setting::load(const std::string &path) -> tl::expected<Setting, std::exception> {
return load(std::filesystem::path(path));
}
}
+4 -18
View File
@@ -12,27 +12,13 @@
#include "seafile/fs/setting.hpp"
#include "util/application_path.hpp"
#include "util/string_util.hpp"
#include "seafile/literals/units.hpp"
namespace seafile::fs
{
using namespace seafile::literals;
namespace
{
tl::expected<Setting, std::exception> readSetting()
{
try
{
const auto path = shell::util::ApplicationPath::get().parent_path() / "seafile.json";
const auto size = std::filesystem::file_size(path);
std::string data(size, '\0');
std::ifstream file(path, std::ios::binary);
file.read(data.data(), size);
return nlohmann::json::parse(data).get<Setting>();
}
catch (const std::exception& ex)
{
return tl::make_unexpected(ex);
}
}
FSP_FILE_SYSTEM_INTERFACE FsInterface = {
.GetVolumeInfo = WinFSPAdapter::GetVolumeInfo,
@@ -62,7 +48,7 @@ namespace seafile::fs
GetSystemTimeAsFileTime(&CreationTime);
const auto setting = readSetting();
const auto setting = Setting::load(shell::util::ApplicationPath::get().parent_path() / "seafile.json");
if (!setting.has_value())
{
spdlog::error(std::format("read setting failed: {}", setting.error().what()));
@@ -70,7 +56,7 @@ namespace seafile::fs
}
VolumeParams.SectorSize = 4096;
VolumeParams.SectorSize = 4_KB;
VolumeParams.SectorsPerAllocationUnit = 1;
VolumeParams.MaxComponentLength = 255;
VolumeParams.VolumeCreationTime = reinterpret_cast<PLARGE_INTEGER>(&CreationTime)->QuadPart;
+20 -30
View File
@@ -9,22 +9,19 @@
#include <unicode/ucnv.h>
#include <unicode/ucsdet.h>
#include <unicode/unistr.h>
#include <string>
#include "util/icu_raii.hpp"
namespace shell::util
{
std::vector<std::string> StringUtil::split(const std::string& s, const std::string& delim)
{
if (delim.empty())
{
namespace shell::util {
std::vector<std::string> StringUtil::split(const std::string &s, const std::string &delim) {
if (delim.empty()) {
return {s};
}
std::vector<std::string> result;
size_t start = 0, pos;
while ((pos = s.find(delim, start)) != std::string::npos)
{
while ((pos = s.find(delim, start)) != std::string::npos) {
result.emplace_back(s.substr(start, pos - start));
start = pos + delim.length();
}
@@ -33,42 +30,36 @@ namespace shell::util
return result;
}
std::string StringUtil::convert_encoding(const std::string& input, const std::string& to)
{
std::string StringUtil::convert_encoding(const std::string &input, const std::string &to) {
return convert_encoding(input, detect_encoding(input), to);
}
std::string StringUtil::detect_encoding(const std::string& data)
{
std::string StringUtil::detect_encoding(const std::string &data) {
UErrorCode status = U_ZERO_ERROR;
const auto detector = UCharsetDetectorPtr(ucsdet_open(&status));
if (U_FAILURE(status))
{
if (U_FAILURE(status)) {
throw std::runtime_error(std::format("ucsdet_open failed:{}", u_errorName(status)));
}
// 设置待检测数据
ucsdet_setText(detector.get(), data.data(), data.size(), &status);
if (U_FAILURE(status))
{
if (U_FAILURE(status)) {
throw std::runtime_error(std::format("ucsdet_open failed,can't set text:{}", u_errorName(status)));
}
// 检测
const UCharsetMatch* match = ucsdet_detect(detector.get(), &status);
const UCharsetMatch *match = ucsdet_detect(detector.get(), &status);
std::string encoding;
if (match && U_SUCCESS(status))
{
if (match && U_SUCCESS(status)) {
encoding = ucsdet_getName(match, &status);
}
return encoding;
}
std::string StringUtil::convert_encoding(const std::string& input, const std::string& from, const std::string& to)
{
std::string StringUtil::convert_encoding(const std::string &input, const std::string &from, const std::string &to) {
UErrorCode status = U_ZERO_ERROR;
// 先获取输出长度
@@ -90,8 +81,7 @@ namespace shell::util
&status
);
if (U_FAILURE(status))
{
if (U_FAILURE(status)) {
throw std::runtime_error(std::format("convert from {} to {} failed:{}", from, to, u_errorName(status)));
}
@@ -100,19 +90,19 @@ namespace shell::util
#ifdef _WIN32
std::wstring StringUtil::utf8_to_utf16le(const std::string& input)
{
std::wstring StringUtil::utf8_to_utf16le(const std::string &input) {
const icu::UnicodeString unicode = icu::UnicodeString::fromUTF8(input);
return std::wstring(unicode.getTerminatedBuffer());
return std::wstring{
reinterpret_cast<const wchar_t *>(unicode.getBuffer()),
static_cast<size_t>(unicode.length())
};
}
std::string StringUtil::utf16le_to_utf8(const std::wstring& input)
{
std::string StringUtil::utf16le_to_utf8(const std::wstring &input) {
return utf16le_to_utf8(input.data());
}
std::string StringUtil::utf16le_to_utf8(const wchar_t* input)
{
std::string StringUtil::utf16le_to_utf8(const wchar_t *input) {
const auto unicode = icu::UnicodeString(input);
std::string utf8;
return unicode.toUTF8String(utf8);