What is the rationale behind std.file.setAttributes ?

Marco Leise Marco.Leise at gmx.de
Sun Dec 29 02:36:58 PST 2013


Am Sat, 28 Dec 2013 15:23:55 +0100
schrieb Jacob Carlborg <doob at me.com>:

> On 2013-12-28 03:46, Marco Leise wrote:
> 
> > Wait a second, what about *setting* attributes? Some difficult
> > ones are:
> >
> > o toggling read-only (for whom? user, group, others?)
> > o executable flag
> > o hidden flag
> >
> > On Windows 'executable' is implicit and based on the extension.
> > On Posix 'hidden' is implicit for a file name beginning with a
> > dot. We can read the hidden bit on POSIX, but we cannot toggle
> > it for example. So we can either not expose these attributes
> > at all, ignore them where not applicable when setting
> > attributes or add a third state "ignore".
> 
> In addition to that Mac OS X has an additional way of indicating if a 
> file is is hidden or not. More similar to how it works on Windows then 
> the naming scheme from Posix.

Oh right, they have a hidden attribute as well. I guess if
Phobos should expose the 'hidden' state of a file it should
write to this attribute, but read both. E.g. for a file
named ".hidden" you could do:

  attribs.hidden = false;

and still

  assert(attribs.hidden == true);

due to the POSIX file naming taking precedence then.

> > Or looking at it another way:
> > DOS attr < POSIX chmod < ACLs
> >
> > How do other programming languages find a common ground?
> 
> On the top of the documentation of the File class in Ruby, it says the 
> following:
> 
> "In the description of File methods, permission bits are a 
> platform-specific set of bits that indicate permissions of a file."
> 
> And
> 
> "On non-Posix operating systems, there may be only the ability to make a 
> file read-only or read-write. In this case, the remaining permission 
> bits will be synthesized to resemble typical values."

Ruby assumes POSIX semantics and directly exposes chmod() and
chown(). Probably because the level of permission control
that POSIX offers is good enough? (Even though that only
allows setting the read-only bit on Windows.)

o they offer one method to set all permission bits in one go
  (chmod)
o other bits (e.g. hidden) cannot be set
o attributes can be queried through a series of separate
  methods: readable, readable_real, world_readable, writable,
  writable_real, world_writable, executable, owned, grpowned.

On Windows grpowned is just: return false;

-- 
Marco



More information about the Digitalmars-d mailing list