Currently Dart provides no access to filesystem permissions at all. It should do so.
_Marked this as blocking #8101._
There is access to file-system permission in:
FileStat.stat(path).then((stat) {
print(stat.mode.toRadixString(8)); // Permission is mapped as octets
print(stat.modeString());
});
There are no way to set these, as of now.
Issue #1834 has been merged into this issue.
cc @sgjesse.
cc @madsager.
_Removed Area-IO label._
_Added Library-IO, Area-Library labels._
_This comment was originally written by @seaneagan_
We also need to be able to access the current process uid and gid and FileStat uid and gid to compare them to each other to determine the process' permissions to that file/directory. Is that part of this bug, or is a separate one needed? I think it may even be possible to support it in windows, see:
_This comment was originally written by @seaneagan_
File permission related bugs: issue #22036, issue #22037
_Removed Type-Defect label._
_Added Type-Enhancement label._
It'd be good to add this. Having to call out to Process.run() is clunky.
Jonas, I think you're the current owner of dart:io?
Can you comment on whether it's feasible to add this?
Ping @sortie
@cskau-g This issue dropped out of my inbox and I forgot about it. Sorry about that.
It's easy enough to come up with a design that can a set Unix style permissions with chmod(2), much like what FileStat.mode currently exposes. However, dart:io works on both Unix and Windows, and generally avoids being designed too specifically for a particular operating system. Windows filesystem permissions are very different from Unix style permissions. Implementing Unix style permissions on Windows isn't really possible. It doesn't have the execute bit and groups work differently.
Indeed that's just file permissions, there's also the owner and group of files, and the complex ACLs supported by Windows, plus the ability to set the modified times of the file, and so on. A proper solution would be to have a full API for these actions. It may need to be different depending on the operating system. I think something like this would be worthwhile and would enhance Dart as a serve side language.
The problem you're trying to solve is just marking a file as executable, a concept that only exists on Unix. Running Process.run("chmod", ["-x", "--", file]) is a bit clunky, yes, but it's small and doable. I don't want to rush a special case API for just that but I'd rather like to look into a full API for filesystem operations.
We also need to be able to access the current process uid and gid and FileStat uid and gid to compare them to each other to determine the process' permissions to that file/directory.
@sortie Yes, we need this.
Running
Process.run("chmod", ["-x", "--", file])is a bit clunky, yes, but it's small and doable.
Calling out to system() isn't just "a bit clunky" - it's fragile and insecure. Case in point, this compiles fine but fails at runtime. -- isn't a valid argument. "What if your file is called -x though?" I hear you ask. Well exactly.
Most helpful comment
It'd be good to add this. Having to call out to
Process.run()is clunky.