parent
1371a8820c
commit
e0b773c6a7
2 changed files with 111 additions and 108 deletions
@ -1,82 +1,84 @@ |
|||||||
#include "dir_entry.h" |
#include "dir_entry.h" |
||||||
|
|
||||||
namespace Bk::Tools { |
namespace Bk { |
||||||
std::string DirEntry::path() |
namespace Tools { |
||||||
{ |
std::string DirEntry::path() |
||||||
return ent.path().string(); |
{ |
||||||
} |
return ent.path().string(); |
||||||
|
} |
||||||
|
|
||||||
std::string DirEntry::absolute_path() |
std::string DirEntry::absolute_path() |
||||||
{ |
{ |
||||||
return std::filesystem::absolute(ent.path()); |
return std::filesystem::absolute(ent.path()); |
||||||
} |
} |
||||||
|
|
||||||
std::string DirEntry::relative_path() |
std::string DirEntry::relative_path() |
||||||
{ |
{ |
||||||
return ent.path().relative_path().string(); |
return ent.path().relative_path().string(); |
||||||
} |
} |
||||||
|
|
||||||
std::string DirEntry::name() |
std::string DirEntry::name() |
||||||
{ |
{ |
||||||
return ent.path().filename(); |
return ent.path().filename(); |
||||||
} |
} |
||||||
|
|
||||||
uintmax_t DirEntry::size() |
uintmax_t DirEntry::size() |
||||||
{ |
{ |
||||||
return ent.file_size(); |
return ent.file_size(); |
||||||
} |
} |
||||||
|
|
||||||
TimePoint<FileClock, Second> DirEntry::last_write() |
TimePoint<FileClock, Second> DirEntry::last_write() |
||||||
{ |
{ |
||||||
return TimePoint<FileClock, Second>(ent.last_write_time()); |
return TimePoint<FileClock, Second>(ent.last_write_time()); |
||||||
} |
} |
||||||
|
|
||||||
bool DirEntry::exists() |
bool DirEntry::exists() |
||||||
{ |
{ |
||||||
return ent.exists(); |
return ent.exists(); |
||||||
} |
} |
||||||
|
|
||||||
bool DirEntry::is(FileType type) |
bool DirEntry::is(FileType type) |
||||||
{ |
{ |
||||||
return this->type() == type; |
return this->type() == type; |
||||||
} |
} |
||||||
|
|
||||||
FileType DirEntry::type() |
FileType DirEntry::type() |
||||||
{ |
{ |
||||||
return ent.status().type(); |
return ent.status().type(); |
||||||
} |
} |
||||||
|
|
||||||
FilePerms DirEntry::perms() |
FilePerms DirEntry::perms() |
||||||
{ |
{ |
||||||
return ent.status().permissions(); |
return ent.status().permissions(); |
||||||
} |
} |
||||||
|
|
||||||
uintmax_t DirEntry::hard_links() |
uintmax_t DirEntry::hard_links() |
||||||
{ |
{ |
||||||
return ent.hard_link_count(); |
return ent.hard_link_count(); |
||||||
} |
} |
||||||
|
|
||||||
bool DirEntry::move(std::string name) |
bool DirEntry::move(std::string name) |
||||||
{ |
|
||||||
std::filesystem::directory_entry new_path(ent.path().parent_path()/name); |
|
||||||
if (exists() && new_path.exists())
|
|
||||||
{ |
{ |
||||||
std::filesystem::rename(ent.path(), new_path.path()/name()); |
std::filesystem::directory_entry new_path(ent.path().parent_path()/name); |
||||||
ent = std::filesystem::directory_entry(new_path.path()); |
if (exists() && new_path.exists())
|
||||||
return true; |
{ |
||||||
|
std::filesystem::rename(ent.path(), new_path.path()/name()); |
||||||
|
ent = std::filesystem::directory_entry(new_path.path()); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
} |
} |
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
bool DirEntry::rename(std::string name) |
bool DirEntry::rename(std::string name) |
||||||
{ |
|
||||||
if (exists())
|
|
||||||
{ |
{ |
||||||
std::filesystem::path new_path = ent.path().parent_path()/name; |
if (exists())
|
||||||
std::filesystem::rename(ent.path(), new_path); |
{ |
||||||
ent = std::filesystem::directory_entry(new_path); |
std::filesystem::path new_path = ent.path().parent_path()/name; |
||||||
return true; |
std::filesystem::rename(ent.path(), new_path); |
||||||
|
ent = std::filesystem::directory_entry(new_path); |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
} |
} |
||||||
return false; |
|
||||||
} |
} |
||||||
} |
} |
@ -1,54 +1,55 @@ |
|||||||
#pragma once |
#pragma once |
||||||
|
|
||||||
|
|
||||||
#include <bakatoolspch.h> |
#include <bakatoolspch.h> |
||||||
#include <bakatools/time/time.h> |
#include <bakatools/time/time.h> |
||||||
|
|
||||||
#define BK_DIR_ENTRY_TYPE(type) const char* type_name() override { return BK_STRINGIFY(type); }\ |
#define BK_DIR_ENTRY_TYPE(type) const char* type_name() override { return BK_STRINGIFY(type); }\ |
||||||
static FileType get_type() { return FileType::type; }\
|
static FileType get_type() { return FileType::type; }\
|
||||||
namespace Bk::Tools { |
namespace Bk { |
||||||
using FileType = std::filesystem::file_type; |
namespace Tools { |
||||||
using FilePerms = std::filesystem::perms; |
using FileType = std::filesystem::file_type; |
||||||
using FileStatus = std::filesystem::file_status; |
using FilePerms = std::filesystem::perms; |
||||||
using CopyOption = std::filesystem::copy_options; |
using FileStatus = std::filesystem::file_status; |
||||||
|
using CopyOption = std::filesystem::copy_options; |
||||||
class DirEntry
|
|
||||||
{ |
class DirEntry
|
||||||
public: |
{ |
||||||
DirEntry(std::string path) |
public: |
||||||
{ |
DirEntry(std::string path) |
||||||
std::filesystem::path p(path); |
{ |
||||||
ent = std::filesystem::directory_entry(p); |
std::filesystem::path p(path); |
||||||
} |
ent = std::filesystem::directory_entry(p); |
||||||
|
} |
||||||
DirEntry(std::filesystem::directory_entry ent) |
|
||||||
: ent(ent) {} |
DirEntry(std::filesystem::directory_entry ent) |
||||||
|
: ent(ent) {} |
||||||
virtual ~DirEntry() {} |
|
||||||
|
virtual ~DirEntry() {} |
||||||
std::string path(); |
|
||||||
std::string absolute_path(); |
std::string path(); |
||||||
std::string relative_path(); |
std::string absolute_path(); |
||||||
std::string name(); |
std::string relative_path(); |
||||||
|
std::string name(); |
||||||
uintmax_t size(); |
|
||||||
TimePoint<FileClock, Second> last_write(); |
uintmax_t size(); |
||||||
bool exists(); |
TimePoint<FileClock, Second> last_write(); |
||||||
FilePerms perms(); |
bool exists(); |
||||||
uintmax_t hard_links(); |
FilePerms perms(); |
||||||
|
uintmax_t hard_links(); |
||||||
bool move(std::string path); |
|
||||||
bool rename(std::string name); |
bool move(std::string path); |
||||||
virtual int remove() { return (int)false; } |
bool rename(std::string name); |
||||||
virtual void copy(std::string path, CopyOption opt) {} |
virtual int remove() { return (int)false; } |
||||||
|
virtual void copy(std::string path, CopyOption opt) {} |
||||||
|
|
||||||
virtual const char* type_name() { return "dir_entry"; } |
|
||||||
FileType type(); |
virtual const char* type_name() { return "dir_entry"; } |
||||||
bool is(FileType type); |
FileType type(); |
||||||
static FileType get_type() { return FileType::unknown; } |
bool is(FileType type); |
||||||
|
static FileType get_type() { return FileType::unknown; } |
||||||
protected: |
|
||||||
std::filesystem::directory_entry ent; |
protected: |
||||||
}; |
std::filesystem::directory_entry ent; |
||||||
|
}; |
||||||
|
} |
||||||
} |
} |
Loading…
Reference in New Issue