libcryfs/src/cryfs/filesystem/CrySymlink.cpp

64 lines
1.7 KiB
C++
Raw Normal View History

2015-04-23 09:18:30 +02:00
#include "CrySymlink.h"
2016-02-11 16:39:42 +01:00
#include <fspp/fuse/FuseErrnoException.h>
2015-04-23 09:18:30 +02:00
#include "CryDevice.h"
#include "CrySymlink.h"
#include "parallelaccessfsblobstore/SymlinkBlobRef.h"
2015-04-23 09:18:30 +02:00
//TODO Get rid of this in favor of exception hierarchy
using fspp::fuse::CHECK_RETVAL;
using fspp::fuse::FuseErrnoException;
namespace bf = boost::filesystem;
using std::string;
using std::vector;
using blockstore::Key;
using boost::none;
using boost::optional;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
2015-09-30 13:21:07 +02:00
using cpputils::dynamic_pointer_move;
using cryfs::parallelaccessfsblobstore::SymlinkBlobRef;
using cryfs::parallelaccessfsblobstore::DirBlobRef;
2015-04-23 09:18:30 +02:00
namespace cryfs {
CrySymlink::CrySymlink(CryDevice *device, unique_ref<DirBlobRef> parent, optional<unique_ref<DirBlobRef>> grandparent, const Key &key)
: CryNode(device, std::move(parent), std::move(grandparent), key) {
2015-04-23 09:18:30 +02:00
}
CrySymlink::~CrySymlink() {
}
unique_ref<SymlinkBlobRef> CrySymlink::LoadBlob() const {
auto blob = CryNode::LoadBlob();
auto symlink_blob = dynamic_pointer_move<SymlinkBlobRef>(blob);
2015-09-30 13:21:07 +02:00
ASSERT(symlink_blob != none, "Blob does not store a symlink");
return std::move(*symlink_blob);
2015-04-23 09:18:30 +02:00
}
fspp::Dir::EntryType CrySymlink::getType() const {
device()->callFsActionCallbacks();
2015-04-23 09:18:30 +02:00
return fspp::Dir::EntryType::SYMLINK;
}
bf::path CrySymlink::target() {
device()->callFsActionCallbacks();
parent()->updateAccessTimestampForChild(key());
auto blob = LoadBlob();
2015-09-30 13:21:07 +02:00
return blob->target();
2015-04-23 09:18:30 +02:00
}
void CrySymlink::remove() {
device()->callFsActionCallbacks();
if (grandparent() != none) {
//TODO Instead of doing nothing when we're in the root directory, handle timestamps in the root dir correctly
(*grandparent())->updateModificationTimestampForChild(parent()->key());
}
removeNode();
}
2015-04-23 09:18:30 +02:00
}