Skip to content

Commit

Permalink
release v1.0.0
Browse files Browse the repository at this point in the history
* fixed atime, mtime and ctime of items in archive
* fixed a warning during a build
  • Loading branch information
andrew-grechkin committed Aug 28, 2020
1 parent 5d2a577 commit 08b07f2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions include/7zip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILib>;
using Format = std::shared_ptr<IFormat>;
Expand Down Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions src/7zip/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const uint64_t*>(&ft));
uint64_t adjust = 11644473600000 * 10000;
date -= adjust;

return Time{static_cast<decltype(Time::tv_sec)>(date / 10000000), static_cast<decltype(Time::tv_nsec)>(date)};
}

ImplArchive::~ImplArchive() noexcept
{
_arc->Close();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/7zip/WriteStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/fuse3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 08b07f2

Please sign in to comment.