summaryrefslogtreecommitdiff
path: root/src/cmd/rmdir.zig
blob: 3033ffa776660f1068377fae84c06b1b5fc09459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const std = @import("std");
const Allocator = std.mem.Allocator;

const types = @import("./lib/types.zig");
const CommandStatus = types.CommandStatus;
const CommandContext = types.CommandContext;

pub const Rmdir = struct {
    path: []const u8,

    pub fn eval(rmdir: Rmdir, ctx: CommandContext) !CommandStatus {
        const dir_path = rmdir.path;

        std.fs.cwd().deleteDir(dir_path) catch |err| {
            const error_msg = switch (err) {
                error.FileNotFound => "The system cannot find the path specified\n",
                error.AccessDenied => "Access denied\n",
                error.DirNotEmpty => "The directory is not empty\n",
                error.FileBusy => "The directory is in use\n",
                error.NotDir => "The system cannot find the path specified\n",
                else => "Unable to remove directory\n",
            };
            var writer = ctx.output_writer;
            try writer.write(error_msg);
            return CommandStatus{ .Code = 1 };
        };

        // No output for successful removal (DOS style)
        return CommandStatus{ .Code = 0 };
    }
};