From bf9496e702b14d625477b311867e0167319daed1 Mon Sep 17 00:00:00 2001 From: asypost Date: Sun, 12 Jul 2026 18:09:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/seafile/fs/seafile_file_system.cpp | 53 ++++++++++++++------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/seafile/fs/seafile_file_system.cpp b/src/seafile/fs/seafile_file_system.cpp index af501a1..13b662a 100644 --- a/src/seafile/fs/seafile_file_system.cpp +++ b/src/seafile/fs/seafile_file_system.cpp @@ -15,6 +15,14 @@ namespace seafile::fs return UNIX_EPOCH_AS_FILETIME + unix_time * HUNDREDS_OF_NANOSECONDS_PER_SECOND; } + + std::string normalize_path(const std::string& path) + { + std::string result = path; + std::ranges::replace(result, '\\', '/'); + return result; + } + int64_t NowFileTime() { FILETIME ft; @@ -111,15 +119,13 @@ namespace seafile::fs NTSTATUS SeafileFileSystem::Open(PWSTR FileName, UINT32 CreateOptions, UINT32 GrantedAccess, PVOID* PFileContext, FSP_FSCTL_FILE_INFO* FileInfo) { - const bool expect_dir = (CreateOptions & FILE_DIRECTORY_FILE) != 0; - if (repo_id.empty()) { return STATUS_OBJECT_NAME_NOT_FOUND; } - const auto path = shell::util::StringUtil::utf16le_to_utf8(FileName); - if (wcscmp(FileName, L"\\") == 0) + const auto path = normalize_path(shell::util::StringUtil::utf16le_to_utf8(FileName)); + if (path == "/") { auto repo = api.repoInfo(repo_id, token, token_type); if (!repo.has_value()) @@ -130,28 +136,25 @@ namespace seafile::fs return STATUS_SUCCESS; } - if (expect_dir) + if (const auto dirInfo = api.dirDetail(repo_id, path, token, token_type); dirInfo.has_value()) { - if (const auto dirInfo = api.dirDetail(repo_id, path, token, token_type); dirInfo.has_value()) - { - const auto& info = dirInfo.value(); - const auto ctx = new SeaFileContext{info.repo_id, info.path, SeaFileContext::Type::DIRECTORY, 0, ""}; - *PFileContext = ctx; - SetFileInfo(FileInfo,FILE_ATTRIBUTE_DIRECTORY, 0, 0); - return STATUS_SUCCESS; - } + const auto& info = dirInfo.value(); + const auto ctx = new SeaFileContext{info.repo_id, info.path, SeaFileContext::Type::DIRECTORY, 0, ""}; + *PFileContext = ctx; + SetFileInfo(FileInfo,FILE_ATTRIBUTE_DIRECTORY, 0, 0); + return STATUS_SUCCESS; } - else + + + if (const auto fileInfo = api.fileDetail(repo_id, path, token, token_type); fileInfo.has_value()) { - if (const auto fileInfo = api.fileDetail(repo_id, path, token, token_type); fileInfo.has_value()) - { - const auto& info = fileInfo.value(); - const auto ctx = new SeaFileContext(repo_id, path, SeaFileContext::Type::FILE, info.size, ""); - *PFileContext = ctx; - SetFileInfo(FileInfo,FILE_ATTRIBUTE_ARCHIVE, 0, 0); - return STATUS_SUCCESS; - } + const auto& info = fileInfo.value(); + const auto ctx = new SeaFileContext(repo_id, path, SeaFileContext::Type::FILE, info.size, ""); + *PFileContext = ctx; + SetFileInfo(FileInfo,FILE_ATTRIBUTE_ARCHIVE, 0, 0); + return STATUS_SUCCESS; } + return STATUS_OBJECT_NAME_NOT_FOUND; } @@ -179,7 +182,7 @@ namespace seafile::fs { const auto fc = static_cast(FileContext); *PBytesTransferred = 0; - const auto path = std::ranges::replace(fc->path,'\\','/'); + const auto path = std::ranges::replace(fc->path, '\\', '/'); const auto entries_result = api.repoDir(fc->repo_id, fc->path, token, token_type); if (entries_result.has_value()) @@ -200,7 +203,7 @@ namespace seafile::fs } for (auto i = start; i < entries.size(); ++i) { - const auto entry = entries[i]; + const auto& entry = entries[i]; const auto entry_name = shell::util::StringUtil::utf8_to_utf16le(entry.name); const auto size = sizeof(FSP_FSCTL_DIR_INFO) + ((entry_name.size() + 1) * sizeof(WCHAR)); @@ -233,7 +236,7 @@ namespace seafile::fs return STATUS_SUCCESS; } - std::cout<