fix: create ~/.cache and ~/.config if they do not exist
This commit is contained in:
		
							parent
							
								
									55259b3ba1
								
							
						
					
					
						commit
						d9087f9884
					
				
					 1 changed files with 18 additions and 6 deletions
				
			
		
							
								
								
									
										24
									
								
								src/main.zig
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/main.zig
									
										
									
									
									
								
							| 
						 | 
					@ -354,10 +354,16 @@ fn get_app_config_dir(appname: []const u8) ![]const u8 {
 | 
				
			||||||
        dir
 | 
					        dir
 | 
				
			||||||
    else if (std.posix.getenv("XDG_CONFIG_HOME")) |xdg|
 | 
					    else if (std.posix.getenv("XDG_CONFIG_HOME")) |xdg|
 | 
				
			||||||
        try std.fmt.bufPrint(&local.config_dir_buffer, "{s}/{s}", .{ xdg, appname })
 | 
					        try std.fmt.bufPrint(&local.config_dir_buffer, "{s}/{s}", .{ xdg, appname })
 | 
				
			||||||
    else if (std.posix.getenv("HOME")) |home|
 | 
					    else if (std.posix.getenv("HOME")) |home| ret: {
 | 
				
			||||||
        try std.fmt.bufPrint(&local.config_dir_buffer, "{s}/.config/{s}", .{ home, appname })
 | 
					        const dir = try std.fmt.bufPrint(&local.config_dir_buffer, "{s}/.config", .{home});
 | 
				
			||||||
    else
 | 
					        std.fs.makeDirAbsolute(dir) catch |e| switch (e) {
 | 
				
			||||||
 | 
					            error.PathAlreadyExists => {},
 | 
				
			||||||
 | 
					            else => return e,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        break :ret try std.fmt.bufPrint(&local.config_dir_buffer, "{s}/.config/{s}", .{ home, appname });
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
        return error.AppConfigDirUnavailable;
 | 
					        return error.AppConfigDirUnavailable;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
    local.config_dir = config_dir;
 | 
					    local.config_dir = config_dir;
 | 
				
			||||||
    std.fs.makeDirAbsolute(config_dir) catch |e| switch (e) {
 | 
					    std.fs.makeDirAbsolute(config_dir) catch |e| switch (e) {
 | 
				
			||||||
        error.PathAlreadyExists => {},
 | 
					        error.PathAlreadyExists => {},
 | 
				
			||||||
| 
						 | 
					@ -379,10 +385,16 @@ fn get_app_cache_dir(appname: []const u8) ![]const u8 {
 | 
				
			||||||
        dir
 | 
					        dir
 | 
				
			||||||
    else if (std.posix.getenv("XDG_CACHE_HOME")) |xdg|
 | 
					    else if (std.posix.getenv("XDG_CACHE_HOME")) |xdg|
 | 
				
			||||||
        try std.fmt.bufPrint(&local.cache_dir_buffer, "{s}/{s}", .{ xdg, appname })
 | 
					        try std.fmt.bufPrint(&local.cache_dir_buffer, "{s}/{s}", .{ xdg, appname })
 | 
				
			||||||
    else if (std.posix.getenv("HOME")) |home|
 | 
					    else if (std.posix.getenv("HOME")) |home| ret: {
 | 
				
			||||||
        try std.fmt.bufPrint(&local.cache_dir_buffer, "{s}/.cache/{s}", .{ home, appname })
 | 
					        const dir = try std.fmt.bufPrint(&local.cache_dir_buffer, "{s}/.cache", .{home});
 | 
				
			||||||
    else
 | 
					        std.fs.makeDirAbsolute(dir) catch |e| switch (e) {
 | 
				
			||||||
 | 
					            error.PathAlreadyExists => {},
 | 
				
			||||||
 | 
					            else => return e,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        break :ret try std.fmt.bufPrint(&local.cache_dir_buffer, "{s}/.cache/{s}", .{ home, appname });
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
        return error.AppCacheDirUnavailable;
 | 
					        return error.AppCacheDirUnavailable;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
    local.cache_dir = cache_dir;
 | 
					    local.cache_dir = cache_dir;
 | 
				
			||||||
    std.fs.makeDirAbsolute(cache_dir) catch |e| switch (e) {
 | 
					    std.fs.makeDirAbsolute(cache_dir) catch |e| switch (e) {
 | 
				
			||||||
        error.PathAlreadyExists => {},
 | 
					        error.PathAlreadyExists => {},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue