Implemented CryDir opening
This commit is contained in:
parent
abc8811e17
commit
d2cba6cfe6
@ -1,3 +1,3 @@
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryErrnoException.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryOpenFileList.cpp)
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryErrnoException.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryOpenDir.cpp CryOpenFileList.cpp IdList.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib boost_filesystem)
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "CryDevice.h"
|
||||
#include "CryOpenDir.h"
|
||||
#include "CryFile.h"
|
||||
#include "CryErrnoException.h"
|
||||
|
||||
@ -44,4 +45,8 @@ void CryDir::rmdir() {
|
||||
CHECK_RETVAL(retval);
|
||||
}
|
||||
|
||||
unique_ptr<CryOpenDir> CryDir::opendir() {
|
||||
return make_unique<CryOpenDir>(device(), path());
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace cryfs {
|
||||
class CryDevice;
|
||||
class CryOpenDir;
|
||||
|
||||
class CryDir: public CryNode {
|
||||
public:
|
||||
@ -19,6 +20,8 @@ public:
|
||||
std::unique_ptr<CryFile> createFile(const std::string &name, mode_t mode);
|
||||
std::unique_ptr<CryDir> createDir(const std::string &name, mode_t mode);
|
||||
void rmdir();
|
||||
|
||||
std::unique_ptr<CryOpenDir> opendir();
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDir);
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ CryFile::~CryFile() {
|
||||
}
|
||||
|
||||
std::unique_ptr<CryOpenFile> CryFile::open(int flags) const {
|
||||
return make_unique<CryOpenFile>(base_path(), flags);
|
||||
return make_unique<CryOpenFile>(device(), path(), flags);
|
||||
}
|
||||
|
||||
void CryFile::truncate(off_t size) const {
|
||||
|
42
src/cryfs_lib/CryOpenDir.cpp
Normal file
42
src/cryfs_lib/CryOpenDir.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <cryfs_lib/CryOpenDir.h>
|
||||
|
||||
#include "CryDevice.h"
|
||||
#include "CryErrnoException.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryOpenDir::CryOpenDir(const CryDevice *device, const bf::path &path)
|
||||
:_dir(::opendir((device->RootDir() / path).c_str())) {
|
||||
if (_dir == nullptr) {
|
||||
throw CryErrnoException(errno);
|
||||
}
|
||||
}
|
||||
|
||||
CryOpenDir::~CryOpenDir() {
|
||||
int retval = ::closedir(_dir);
|
||||
CHECK_RETVAL(retval);
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> CryOpenDir::readdir() const {
|
||||
::rewinddir(_dir);
|
||||
|
||||
auto result = make_unique<vector<string>>();
|
||||
|
||||
struct dirent *entry = ::readdir(_dir);
|
||||
while(entry != nullptr) {
|
||||
result->push_back(entry->d_name);
|
||||
entry = ::readdir(_dir);
|
||||
}
|
||||
//On error, ::readdir returns nullptr and sets errno.
|
||||
if (errno != 0) {
|
||||
throw CryErrnoException(errno);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
31
src/cryfs_lib/CryOpenDir.h
Normal file
31
src/cryfs_lib/CryOpenDir.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef CRYFS_LIB_CRYOPENDIR_H_
|
||||
#define CRYFS_LIB_CRYOPENDIR_H_
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "utils/macros.h"
|
||||
|
||||
namespace cryfs {
|
||||
class CryDevice;
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
class CryOpenDir {
|
||||
public:
|
||||
CryOpenDir(const CryDevice *device, const bf::path &path);
|
||||
virtual ~CryOpenDir();
|
||||
|
||||
std::unique_ptr<std::vector<std::string>> readdir() const;
|
||||
private:
|
||||
DIR *_dir;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryOpenDir);
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif /* CRYFS_LIB_CRYOPENDIR_H_ */
|
@ -4,11 +4,12 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "CryErrnoException.h"
|
||||
#include "CryDevice.h"
|
||||
|
||||
using namespace cryfs;
|
||||
|
||||
CryOpenFile::CryOpenFile(const bf::path &path, int flags)
|
||||
:_descriptor(::open(path.c_str(), flags)) {
|
||||
CryOpenFile::CryOpenFile(const CryDevice *device, const bf::path &path, int flags)
|
||||
:_descriptor(::open((device->RootDir() / path).c_str(), flags)) {
|
||||
CHECK_RETVAL(_descriptor);
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,13 @@
|
||||
#include "utils/macros.h"
|
||||
|
||||
namespace cryfs {
|
||||
class CryDevice;
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
class CryOpenFile {
|
||||
public:
|
||||
CryOpenFile(const bf::path &path, int flags);
|
||||
CryOpenFile(const CryDevice *device, const bf::path &path, int flags);
|
||||
virtual ~CryOpenFile();
|
||||
|
||||
void stat(struct ::stat *result) const;
|
||||
|
Loading…
Reference in New Issue
Block a user