commit 8f4f4f5742282f6890611094030ee8219794c7ec
parent c308da0802b3c24a3aa6dbf944c256fcf03b88f0
Author: Jon Eskin <eskinjp@gmail.com>
Date: Mon, 9 May 2022 14:07:07 -0400
os: add mode to mkdir
Signed-off-by: Jon Eskin <eskinjp@gmail.com>
Diffstat:
10 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/cmd/hare/release.ha b/cmd/hare/release.ha
@@ -1,6 +1,7 @@
// License: GPL-3.0
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use bufio;
use errors;
use fmt;
@@ -260,7 +261,7 @@ fn choosekey() (str | release_error) = {
};
const parent = path::set(&buf, home, ".ssh")!;
- os::mkdirs(parent)?;
+ os::mkdirs(parent, 0o755)?;
const path = path::set(&buf, home, ".ssh", "id_ed25519")!;
const cmd = match (exec::cmd("ssh-keygen", "-t", "ed25519", "-f", path)) {
diff --git a/cmd/hare/schedule.ha b/cmd/hare/schedule.ha
@@ -3,6 +3,7 @@
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
// (c) 2021 Thomas Bracht Laumann Jespersen <t@laumann.xyz>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use encoding::hex;
use fmt;
use fs;
@@ -232,7 +233,7 @@ fn sched_hare_object(
path::set(&buf, plan.context.cache)!;
path::add(&buf, namespace...)!;
const path = path::string(&buf);
- match (os::mkdirs(path)) {
+ match (os::mkdirs(path, 0o755)) {
case void => void;
case let err: fs::error =>
fmt::fatalf("Error: mkdirs {}: {}", path,
diff --git a/dirs/xdg.ha b/dirs/xdg.ha
@@ -2,6 +2,7 @@
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
// (c) 2022 Sebastian <sebastian@sebsite.pw>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use fmt;
use fs;
use os;
@@ -16,7 +17,7 @@ fn lookup(prog: str, var: str, default: str) str = {
const path = path::add(&buf, s, prog)!;
match (os::stat(path)) {
case let err: fs::error =>
- os::mkdirs(path)!;
+ os::mkdirs(path, 0o755)!;
return path;
case let st: fs::filestat =>
if (fs::isdir(st.mode)) {
@@ -28,7 +29,7 @@ fn lookup(prog: str, var: str, default: str) str = {
const home = os::getenv("HOME") as str;
const path = path::set(&buf, home, default, prog)!;
- match (os::mkdirs(path)) {
+ match (os::mkdirs(path, 0o755)) {
case void =>
yield;
case let err: fs::error =>
diff --git a/fs/fs.ha b/fs/fs.ha
@@ -5,6 +5,7 @@
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
// (c) 2021 Thomas Bracht Laumann Jespersen <t@laumann.xyz>
// (c) 2021 Umar Getagazov <umar@handlerug.me>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use errors;
use io;
use path;
@@ -195,27 +196,27 @@ export fn readlink(fs: *fs, path: str) (str | error) = {
};
// Creates a directory.
-export fn mkdir(fs: *fs, path: str) (void | error) = {
+export fn mkdir(fs: *fs, path: str, mode: mode) (void | error) = {
match (fs.mkdir) {
case null =>
return errors::unsupported;
case let f: *mkdirfunc =>
- return f(fs, path);
+ return f(fs, path, mode);
};
};
// Makes a directory, and all non-extant directories in its path.
-export fn mkdirs(fs: *fs, path: str) (void | error) = {
+export fn mkdirs(fs: *fs, path: str, mode: mode) (void | error) = {
let parent = path::dirname(path);
if (path != parent) {
- match (mkdirs(fs, parent)) {
+ match (mkdirs(fs, parent, mode)) {
case errors::exists => void;
case void => void;
case let err: error =>
return err;
};
};
- match (mkdir(fs, path)) {
+ match (mkdir(fs, path, mode)) {
case errors::exists => void;
case void => void;
case let err: error =>
diff --git a/fs/types.ha b/fs/types.ha
@@ -2,6 +2,7 @@
// (c) 2021 Alexey Yerin <yyp@disroot.org>
// (c) 2021 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use errors;
use io;
use path;
@@ -196,7 +197,7 @@ export type removefunc = fn(fs: *fs, path: str) (void | error);
export type renamefunc = fn(fs: *fs, oldpath: str, newpath: str) (void | error);
export type iterfunc = fn(fs: *fs, path: str) (*iterator | error);
export type statfunc = fn(fs: *fs, path: str) (filestat | error);
-export type mkdirfunc = fn(fs: *fs, path: str) (void | error);
+export type mkdirfunc = fn(fs: *fs, path: str, mode: mode) (void | error);
export type rmdirfunc = fn(fs: *fs, path: str) (void | error);
export type chmodfunc = fn(fs: *fs, path: str, mode: mode) (void | error);
export type chownfunc = fn(fs: *fs, path: str, uid: uint, gid: uint) (void | error);
diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha
@@ -1,6 +1,7 @@
// License: MPL-2.0
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use bytes;
use errors;
use encoding::utf8;
@@ -283,9 +284,9 @@ fn fs_rmdir(fs: *fs::fs, path: str) (void | fs::error) = {
};
};
-fn fs_mkdir(fs: *fs::fs, path: str) (void | fs::error) = {
+fn fs_mkdir(fs: *fs::fs, path: str, mode: fs::mode) (void | fs::error) = {
let fs = fs: *os_filesystem;
- match (rt::mkdirat(fs.dirfd, path, 0o755)) {
+ match (rt::mkdirat(fs.dirfd, path, mode: uint)) {
case let err: rt::errno =>
switch (err) {
case rt::EISDIR =>
diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha
@@ -3,6 +3,7 @@
// (c) 2022 Bor Grošelj Simić <bor.groseljsimic@telemach.net>
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use bytes;
use errors;
use encoding::utf8;
@@ -313,9 +314,9 @@ fn fs_rmdir(fs: *fs::fs, path: str) (void | fs::error) = {
};
};
-fn fs_mkdir(fs: *fs::fs, path: str) (void | fs::error) = {
+fn fs_mkdir(fs: *fs::fs, path: str, mode: fs::mode) (void | fs::error) = {
let fs = fs: *os_filesystem;
- match (rt::mkdirat(fs.dirfd, path, 0o755)) {
+ match (rt::mkdirat(fs.dirfd, path, mode: uint)) {
case let err: rt::errno =>
return errno_to_fs(err);
case void => void;
diff --git a/os/fs.ha b/os/fs.ha
@@ -2,6 +2,7 @@
// (c) 2021 Alexey Yerin <yyp@disroot.org>
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use fs;
use io;
use path;
@@ -38,10 +39,10 @@ export fn readdir(path: str) ([]fs::dirent | fs::error) = fs::readdir(cwd, path)
export fn stat(path: str) (fs::filestat | fs::error) = fs::stat(cwd, path);
// Creates a directory.
-export fn mkdir(path: str) (void | fs::error) = fs::mkdir(cwd, path);
+export fn mkdir(path: str, mode: fs::mode) (void | fs::error) = fs::mkdir(cwd, path, mode);
// Creates a directory, and all non-extant directories in its path.
-export fn mkdirs(path: str) (void | fs::error) = fs::mkdirs(cwd, path);
+export fn mkdirs(path: str, mode: fs::mode) (void | fs::error) = fs::mkdirs(cwd, path, mode);
// Removes a directory. The target directory must be empty; see [[rmdirall]] to
// remove its contents as well.
diff --git a/temp/+freebsd.ha b/temp/+freebsd.ha
@@ -2,6 +2,7 @@
// (c) 2022 Alexey Yerin <yyp@disroot.org>
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use crypto::random;
use encoding::hex;
use errors;
@@ -101,7 +102,7 @@ export fn dir() str = {
static let buf = path::buffer { ... };
path::set(&buf, get_tmpdir(), name)!;
const path = path::string(&buf);
- match (os::mkdir(path)) {
+ match (os::mkdir(path,0o755)) {
case let err: fs::error => abort("Could not create temp directory");
case void => void;
};
diff --git a/temp/+linux.ha b/temp/+linux.ha
@@ -2,6 +2,7 @@
// (c) 2022 Alexey Yerin <yyp@disroot.org>
// (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Eyal Sawady <ecs@d2evs.net>
+// (c) 2022 Jon Eskin <eskinjp@gmail.com>
use crypto::random;
use encoding::hex;
use errors;
@@ -115,7 +116,7 @@ export fn dir() str = {
static let buf = path::buffer { ... };
path::set(&buf, get_tmpdir(), name)!;
const path = path::string(&buf);
- match (os::mkdir(path)) {
+ match (os::mkdir(path, 0o755)) {
case let err: fs::error => abort("Could not create temp directory");
case void => void;
};