From 08b07f2ada5e1090c4a99aea5f94a98d19bc9ae4 Mon Sep 17 00:00:00 2001 From: Andrew Grechkin Date: Fri, 28 Aug 2020 17:09:24 +0200 Subject: [PATCH] release v1.0.0 * fixed atime, mtime and ctime of items in archive * fixed a warning during a build --- CMakeLists.txt | 2 +- README.md | 2 ++ include/7zip.hpp | 4 ++++ src/7zip/Archive.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/7zip/WriteStream.cpp | 2 +- src/fuse3.cpp | 5 +++++ src/main.cpp | 3 --- 7 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0a2b3a..891f6ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 3.12 FATAL_ERROR) project (fuse3-p7zip - VERSION 0.9.4 + VERSION 1.0.0 DESCRIPTION "fuse3 file system that uses the p7zip library to mount archives" LANGUAGES CXX ) diff --git a/README.md b/README.md index 7eab840..4f9db16 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ $ fusermount -u /tmp/mnt ``` ## Description +https://github.com/andrew-grechkin/fuse3-p7zip + This application is an implementation of Filesystem in Userspace (FUSE) version 3 backed by 7zip library. It's able to mount any archive supported by 7zip as a filesysterm mountpoint and have read only access to any file in this archive. diff --git a/include/7zip.hpp b/include/7zip.hpp index a71971a..f771dc3 100644 --- a/include/7zip.hpp +++ b/include/7zip.hpp @@ -25,6 +25,7 @@ namespace sevenzip { struct Guid; using Stat = struct stat; + using Time = struct timespec; using Path = std::filesystem::path; using Lib = std::unique_ptr; using Format = std::shared_ptr; @@ -159,6 +160,9 @@ namespace sevenzip { std::string comment() const; Size size() const; Size size_packed() const; + Time atime() const; + Time mtime() const; + Time ctime() const; bool is_file() const; bool is_dir() const; diff --git a/src/7zip/Archive.cpp b/src/7zip/Archive.cpp index 81a70d1..786c522 100644 --- a/src/7zip/Archive.cpp +++ b/src/7zip/Archive.cpp @@ -8,6 +8,15 @@ namespace sevenzip { const UInt64 max_check_size = 100 * 1024 * 1024; + Time _to_time(const FILETIME& ft) + { + uint64_t date = *(reinterpret_cast(&ft)); + uint64_t adjust = 11644473600000 * 10000; + date -= adjust; + + return Time{static_cast(date / 10000000), static_cast(date)}; + } + ImplArchive::~ImplArchive() noexcept { _arc->Close(); @@ -288,6 +297,33 @@ namespace sevenzip { return 0; } + Time ImplArchive::ci_iterator::atime() const + { + NWindows::NCOM::CPropVariant prop; + auto res = impl->get_prop(kpidATime, prop); + if (res == S_OK && prop.vt == VT_FILETIME && (prop.filetime.dwLowDateTime || prop.filetime.dwHighDateTime)) + return _to_time(prop.filetime); + return Time{0, 0}; + } + + Time ImplArchive::ci_iterator::mtime() const + { + NWindows::NCOM::CPropVariant prop; + auto res = impl->get_prop(kpidMTime, prop); + if (res == S_OK && prop.vt == VT_FILETIME && (prop.filetime.dwLowDateTime || prop.filetime.dwHighDateTime)) + return _to_time(prop.filetime); + return Time{0, 0}; + } + + Time ImplArchive::ci_iterator::ctime() const + { + NWindows::NCOM::CPropVariant prop; + auto res = impl->get_prop(kpidCTime, prop); + if (res == S_OK && prop.vt == VT_FILETIME && (prop.filetime.dwLowDateTime || prop.filetime.dwHighDateTime)) + return _to_time(prop.filetime); + return Time{0, 0}; + } + bool ImplArchive::ci_iterator::is_file() const { return !is_dir(); diff --git a/src/7zip/WriteStream.cpp b/src/7zip/WriteStream.cpp index 25948b1..288a81c 100644 --- a/src/7zip/WriteStream.cpp +++ b/src/7zip/WriteStream.cpp @@ -83,7 +83,7 @@ namespace sevenzip { { LogTrace(); auto pos = std::ftell(_file); - ftruncate(_file->_fileno, newSize); + CheckResult(ftruncate(_file->_fileno, newSize) == 0, "ftruncate"); std::fseek(_file, pos, SEEK_SET); LogDebug("SetSize: %d", newSize); return check_error(_file); diff --git a/src/fuse3.cpp b/src/fuse3.cpp index 6cdeedf..254e66f 100644 --- a/src/fuse3.cpp +++ b/src/fuse3.cpp @@ -120,6 +120,7 @@ void* Fuse::Operations::cb_init(fuse_conn_info*, fuse_config* cfg) return ctx->private_data; } + void Fuse::Operations::cb_destroy(void*) {} int Fuse::Operations::cb_getattr(const char* path, struct stat* stbuf, fuse_file_info*) @@ -223,6 +224,10 @@ ssize_t Fuse::execute(sevenzip::IArchive* arc) auto file_stat = arc->stat(); file_stat.st_mode &= ~S_IFMT; file_stat.st_size = it.size(); + file_stat.st_atim = it.atime(); + file_stat.st_mtim = it.mtime(); + file_stat.st_ctim = it.ctime(); + if (it.is_dir()) { file_stat.st_mode |= S_IFDIR | 0775; } else { diff --git a/src/main.cpp b/src/main.cpp index dd96c30..d8dcea7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,9 +3,6 @@ #include "fuse3.hpp" #include "logger.hpp" -// TODO -// verbose --version - int main(int argc, char** argv, char** env) try { auto override_library = std::getenv("FUSE3_P7ZIP_LIBRARY");