MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ensure ant works with legacy $HOME/.ant

+44
+24
src/pkg/root.zig
··· 32 32 return value; 33 33 } 34 34 35 + fn getLegacyAntDirIfExists(allocator: std.mem.Allocator) !?[]const u8 { 36 + const home = try getHomeDir(allocator); 37 + defer allocator.free(home); 38 + 39 + const dir = try std.fmt.allocPrint(allocator, "{s}/.ant", .{home}); 40 + std.fs.cwd().access(dir, .{}) catch { 41 + allocator.free(dir); 42 + return null; 43 + }; 44 + return dir; 45 + } 46 + 35 47 pub const PkgError = enum(c_int) { 36 48 ok = 0, 37 49 out_of_memory = -1, ··· 249 261 250 262 fn getDefaultCacheDir(allocator: std.mem.Allocator) ![]const u8 { 251 263 if (builtin.os.tag != .windows) { 264 + if (try getLegacyAntDirIfExists(allocator)) |dir| { 265 + defer allocator.free(dir); 266 + return std.fmt.allocPrint(allocator, "{s}/pkg", .{dir}); 267 + } 252 268 if (getAbsoluteEnv("XDG_CACHE_HOME")) |base| { 253 269 return std.fmt.allocPrint(allocator, "{s}/ant/pkg", .{base}); 254 270 } ··· 2958 2974 2959 2975 fn getGlobalDir(allocator: std.mem.Allocator) ![]const u8 { 2960 2976 if (builtin.os.tag != .windows) { 2977 + if (try getLegacyAntDirIfExists(allocator)) |dir| { 2978 + defer allocator.free(dir); 2979 + return std.fmt.allocPrint(allocator, "{s}/pkg/global", .{dir}); 2980 + } 2961 2981 if (getAbsoluteEnv("XDG_DATA_HOME")) |base| { 2962 2982 return std.fmt.allocPrint(allocator, "{s}/ant/pkg/global", .{base}); 2963 2983 } ··· 2975 2995 const home = try getHomeDir(allocator); 2976 2996 defer allocator.free(home); 2977 2997 if (builtin.os.tag != .windows) { 2998 + if (try getLegacyAntDirIfExists(allocator)) |dir| { 2999 + defer allocator.free(dir); 3000 + return std.fmt.allocPrint(allocator, "{s}/bin", .{dir}); 3001 + } 2978 3002 return std.fmt.allocPrint(allocator, "{s}/.local/bin", .{home}); 2979 3003 } 2980 3004 return std.fmt.allocPrint(allocator, "{s}/.ant/bin", .{home});
+20
src/utils.c
··· 58 58 return (written < 0 || (size_t)written >= out_size) ? -1 : 0; 59 59 } 60 60 61 + static int ant_legacy_home_path(char *out, size_t out_size, const char *suffix) { 62 + const char *home = ant_home_dir(); 63 + if (!home) return -1; 64 + return ant_join_app_path(out, out_size, home, ".ant", suffix); 65 + } 66 + 67 + static bool ant_legacy_home_exists(void) { 68 + char path[4096]; 69 + if (ant_legacy_home_path(path, sizeof(path), NULL) != 0) return false; 70 + struct stat st; 71 + return stat(path, &st) == 0; 72 + } 73 + 61 74 static int ant_xdg_path( 62 75 char *out, size_t out_size, 63 76 const char *env_name, ··· 69 82 if (!home) return -1; 70 83 return ant_join_app_path(out, out_size, home, ".ant", suffix); 71 84 #else 85 + if (ant_legacy_home_exists()) { 86 + return ant_legacy_home_path(out, out_size, suffix); 87 + } 88 + 72 89 const char *base = ant_absolute_env(env_name); 73 90 if (base) return ant_join_app_path(out, out_size, base, "ant", suffix); 74 91 ··· 126 143 #ifdef _WIN32 127 144 int written = snprintf(out, out_size, "%s/.ant/bin", home); 128 145 #else 146 + if (ant_legacy_home_exists()) { 147 + return ant_legacy_home_path(out, out_size, "bin"); 148 + } 129 149 int written = snprintf(out, out_size, "%s/.local/bin", home); 130 150 #endif 131 151 return (written < 0 || (size_t)written >= out_size) ? -1 : 0;