emory/fs: initial experiments in xattr iteration
This commit is contained in:
parent
6ca1fe1670
commit
d83601755c
@ -26,6 +26,12 @@ add_library(emory
|
||||
emory/chunk/params.hpp
|
||||
emory/chunk/region.cpp
|
||||
emory/chunk/region.hpp
|
||||
emory/fs/acl.cpp
|
||||
emory/fs/acl.hpp
|
||||
emory/fs/ostream.cpp
|
||||
emory/fs/ostream.hpp
|
||||
emory/fs/xattr.cpp
|
||||
emory/fs/xattr.hpp
|
||||
)
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 014401899280a15b8b05312a4f91e379b875b634
|
||||
Subproject commit 5fb87ea4c4e5f30c9ee40a56e3487c0358d69783
|
0
emory/fs/acl.cpp
Normal file
0
emory/fs/acl.cpp
Normal file
13
emory/fs/acl.hpp
Normal file
13
emory/fs/acl.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace emory::fs {
|
||||
|
||||
}
|
0
emory/fs/ostream.cpp
Normal file
0
emory/fs/ostream.cpp
Normal file
16
emory/fs/ostream.hpp
Normal file
16
emory/fs/ostream.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace emory::fs {
|
||||
}
|
1
emory/fs/xattr.cpp
Normal file
1
emory/fs/xattr.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "xattr.hpp"
|
51
emory/fs/xattr.hpp
Normal file
51
emory/fs/xattr.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cruft/util/posix/fd.hpp>
|
||||
#include <cruft/util/std.hpp>
|
||||
#include <cruft/util/view.hpp>
|
||||
#include <cruft/util/expected.hpp>
|
||||
#include <cruft/util/string.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace emory::fs {
|
||||
class xattr {
|
||||
public:
|
||||
xattr (cruft::posix::fd&&);
|
||||
|
||||
void set (char const *name, cruft::view<u08 const*> data);
|
||||
|
||||
cruft::expected<int,int>
|
||||
get (char const *name, cruft::view<u08 const*> data);
|
||||
|
||||
|
||||
struct keylist {
|
||||
explicit keylist (std::string &&);
|
||||
|
||||
auto begin (void)& { return m_tokeniser.begin (); }
|
||||
auto end (void)& { return m_tokeniser.end (); }
|
||||
|
||||
auto begin (void) const& { return m_tokeniser.begin (); }
|
||||
auto end (void) const& { return m_tokeniser.end (); }
|
||||
|
||||
auto & data (void) & { return m_data; }
|
||||
auto const& data (void) const& { return m_data; }
|
||||
|
||||
std::string m_data;
|
||||
cruft::tokeniser<char const*> m_tokeniser;
|
||||
};
|
||||
|
||||
keylist list (void);
|
||||
|
||||
private:
|
||||
cruft::posix::fd m_fd;
|
||||
};
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include <cruft/util/bitwise.hpp>
|
||||
#include <cruft/util/posix/except.hpp>
|
||||
#include <cruft/util/posix/util.hpp>
|
||||
#include <cruft/util/posix/ostream.hpp>
|
||||
#include <cruft/util/string.hpp>
|
||||
|
||||
#include <iostream>
|
||||
@ -17,89 +19,6 @@
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct type_printer {
|
||||
type_printer (struct stat const &_data)
|
||||
: data (_data)
|
||||
{ ; }
|
||||
|
||||
struct stat const &data;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream& operator<< (std::ostream &os, type_printer const &val)
|
||||
{
|
||||
os << "[ ";
|
||||
if (val.data.st_mode & S_ISUID) os << "SUID, ";
|
||||
if (val.data.st_mode & S_ISGID) os << "SGID, ";
|
||||
if (val.data.st_mode & S_ISVTX) os << "STICKY, ";
|
||||
|
||||
os << "{ user: " << (val.data.st_mode & S_IRUSR ? 'r' : '_')
|
||||
<< (val.data.st_mode & S_IWUSR ? 'w' : '_')
|
||||
<< (val.data.st_mode & S_IXUSR ? 'x' : '_')
|
||||
<< " }, "
|
||||
<< "{ group: " << (val.data.st_mode & S_IRGRP ? 'r' : '_')
|
||||
<< (val.data.st_mode & S_IWGRP ? 'w' : '_')
|
||||
<< (val.data.st_mode & S_IXGRP ? 'x' : '_')
|
||||
<< " }, "
|
||||
<< "{ group: " << (val.data.st_mode & S_IROTH ? 'r' : '_')
|
||||
<< (val.data.st_mode & S_IWOTH ? 'w' : '_')
|
||||
<< (val.data.st_mode & S_IXOTH ? 'x' : '_')
|
||||
<< " }";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct mode_printer {
|
||||
mode_printer (struct stat const &_data)
|
||||
: data (_data)
|
||||
{ ; }
|
||||
|
||||
struct stat const &data;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream& operator<< (std::ostream &os, mode_printer const &val)
|
||||
{
|
||||
return S_ISREG (val.data.st_mode) ? os << "REGULAR"
|
||||
: S_ISDIR (val.data.st_mode) ? os << "DIRECTORY"
|
||||
: S_ISCHR (val.data.st_mode) ? os << "CHARACTER"
|
||||
: S_ISBLK (val.data.st_mode) ? os << "BLOCK"
|
||||
: S_ISFIFO (val.data.st_mode) ? os << "FIFO"
|
||||
: S_ISLNK (val.data.st_mode) ? os << "SYMLINK"
|
||||
: S_ISSOCK (val.data.st_mode) ? os << "SOCKET"
|
||||
: (throw std::invalid_argument ("Unhandled mode_t"), os << "_error");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream& operator<< (std::ostream &os, struct stat const &val)
|
||||
{
|
||||
return os << "{ dev: " << val.st_dev
|
||||
<< ", ino: " << val.st_ino
|
||||
<< ", type: " << type_printer (val)
|
||||
<< ", mode: " << mode_printer (val)
|
||||
<< ", uid: " << val.st_uid
|
||||
<< ", gid: " << val.st_gid
|
||||
<< ", size: " << val.st_size
|
||||
<< ", blocksize: " << val.st_blksize
|
||||
<< " }";
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static void do_stat (char const *path)
|
||||
{
|
||||
struct stat buffer;
|
||||
cruft::posix::error::try_call (stat, path, &buffer);
|
||||
std::cout << buffer;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void do_xattr (char const *path)
|
||||
{
|
||||
@ -169,7 +88,7 @@ int main (int argc, char **argv)
|
||||
std::cout << "{ stat: ";
|
||||
|
||||
char const *path = argv[i];
|
||||
do_stat (path);
|
||||
std::cout << cruft::posix::stat (path);
|
||||
do_xattr (path);
|
||||
do_acl (path);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user