Skip to content

Commit

Permalink
Properly close files on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
AMythicDev committed May 25, 2024
1 parent eea19c7 commit fd5904d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ zig build --release=safe
- [x] Install versions (master, stable, x.y.z)
- [x] Remove versions
- [x] List down installed versions
- [ ] Override zig versions to be used under certain directories
- [x] Add override for zig versions to be used under certain directories
- [ ] Remove overrides

## License
`zigvm` is licensed under the Apache License 2.0. See the [LICENSE](./LICENSE) file.
1 change: 1 addition & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub fn main() !void {
const command = try Cli.read_args(alloc);

const cp = try CommonPaths.resolve(alloc);
defer cp.clone();

switch (command) {
Cli.install => |version| {
Expand Down
9 changes: 9 additions & 0 deletions src/paths.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub const CommonPaths = struct {
download_dir: Dir,
overrides: File,

const Self = @This();

var zigvm_root_path: []const u8 = undefined;

pub fn resolve(alloc: Allocator) !@This() {
Expand Down Expand Up @@ -37,4 +39,11 @@ pub const CommonPaths = struct {
pub fn get_zigvm_root() []const u8 {
return zigvm_root_path;
}

pub fn clone(self: *Self) void {
self.overrides.close();
self.download_dir.close();
self.install_dir.close();
self.zigvm_root.close();
}
};

0 comments on commit fd5904d

Please sign in to comment.