Boost logo

Boost :

From: mfdylan (dylan_at_[hidden])
Date: 2002-02-24 18:38:24

--- In boost_at_y..., Beman Dawes <bdawes_at_a...> wrote:
> At 04:29 PM 2/23/2002, mfdylan wrote:
> Have you looked at the way attributes are handled in Dietmar's and
> submissions? See their entries in

Another thing that's needed: a way to test whether the currently
logged in user can read write or execute a file (ie POSIX 'access').
That's not trivial with the proposed set of attributes given.

Btw these are the functions I have currently. I like the idea of
unifying the attribute set/get interface however, so I will almost
definitely change this.

bool exists(name_t name);
size_type size(name_t name);
bool remove(name_t name);
bool copy(name_t source, name_t dest);
bool move(name_t source, name_t dest);
bool readable(name_t name);
bool writeable(name_t name);
bool executable(name_t name);
time_type modified(name_t name);
time_type accessed(name_t name);
bool is_directory(name_t name);
bool touch(name_t name);
bool chown(name_t name, string_t owner, string_t group);
bool chmod(name_t name, int mode);
string_t owner(name_t name);
string_t group(name_t name);
int mode(name_t name);
string_t getcwd();
bool chdir(name_t name);
bool mkdir(name_t name);

With these types:

enum mode_type
        others_execute = 00001,
        others_write = 00002,
        others_read = 00004,
        group_execute = 00010,
        group_write = 00020,
        group_read = 00040,
        user_execute = 00100,
        user_write = 00200,
        user_read = 00400
        all_execute = others_execute | group_execute | user_execute,
        all_write = others_write | group_write | user_write,
        all_read = others_read | group_read | user_read

struct time_type
        time_type(time_t secs = 0, long nsecs = 0) :
                m_secs(secs), m_nsecs(nsecs)
        { }
        time_t seconds() const { return m_secs; }
        long nanoseconds() const { return m_nsecs; }
        operator time_t () const { return m_secs; }
        time_t m_secs;
        long m_nsecs;

I've written Win32 implementations for all of the above, POSIX
implementations are trivial.
The problem with attributes as I mentioned in another post is that
you need a way to specify upfront exactly which attributes you want
and request them all in one go. Some attributes might be expensive
to determine, others might be better grabbed all in one go, according
to the platform and whether the files are local or remote.
One way is using some sort of type list, but this isn't terribly
amenable to determining at runtime whether a certain attribute is
needed. Furthermore the syntax is bound to be awkward.
Another possibility is something like:

attribute_set attr = attributes(pathname);
string s = attr.get<owner>();

where the 'require' calls are an optional hint to optimise the
eventual request, made through a get() call (which would request all
the information hinted at and cache).
This is fairly pointless for POSIX of course, where stat() returns
basically everything and has no options to specify which bits of data
you do and don't want. But for instance under NT, looking up an
account name for a file owner can be a slow operation (I've seen it
pause for 2 seconds on a regular LAN, no idea why). Also a lot of NT
security calls have a flags parameter that allows you to specify
which bits of information you actually want. I would be extremely
interested to hear from someone with MacOS experience on this matter.


Boost list run by bdawes at, gregod at, cpdaniel at, john at