diff --git a/src/pkg/root.zig b/src/pkg/root.zig index feb0a28..2a80308 100644 --- a/src/pkg/root.zig +++ b/src/pkg/root.zig @@ -32,6 +32,18 @@ fn getAbsoluteEnv(name: [:0]const u8) ?[]const u8 { return value; } +fn getLegacyAntDirIfExists(allocator: std.mem.Allocator) !?[]const u8 { + const home = try getHomeDir(allocator); + defer allocator.free(home); + + const dir = try std.fmt.allocPrint(allocator, "{s}/.ant", .{home}); + std.fs.cwd().access(dir, .{}) catch { + allocator.free(dir); + return null; + }; + return dir; +} + pub const PkgError = enum(c_int) { ok = 0, out_of_memory = -1, @@ -249,6 +261,10 @@ pub const PkgContext = struct { fn getDefaultCacheDir(allocator: std.mem.Allocator) ![]const u8 { if (builtin.os.tag != .windows) { + if (try getLegacyAntDirIfExists(allocator)) |dir| { + defer allocator.free(dir); + return std.fmt.allocPrint(allocator, "{s}/pkg", .{dir}); + } if (getAbsoluteEnv("XDG_CACHE_HOME")) |base| { return std.fmt.allocPrint(allocator, "{s}/ant/pkg", .{base}); } @@ -2958,6 +2974,10 @@ export fn pkg_exec_temp( fn getGlobalDir(allocator: std.mem.Allocator) ![]const u8 { if (builtin.os.tag != .windows) { + if (try getLegacyAntDirIfExists(allocator)) |dir| { + defer allocator.free(dir); + return std.fmt.allocPrint(allocator, "{s}/pkg/global", .{dir}); + } if (getAbsoluteEnv("XDG_DATA_HOME")) |base| { return std.fmt.allocPrint(allocator, "{s}/ant/pkg/global", .{base}); } @@ -2975,6 +2995,10 @@ fn getGlobalBinDir(allocator: std.mem.Allocator) ![]const u8 { const home = try getHomeDir(allocator); defer allocator.free(home); if (builtin.os.tag != .windows) { + if (try getLegacyAntDirIfExists(allocator)) |dir| { + defer allocator.free(dir); + return std.fmt.allocPrint(allocator, "{s}/bin", .{dir}); + } return std.fmt.allocPrint(allocator, "{s}/.local/bin", .{home}); } return std.fmt.allocPrint(allocator, "{s}/.ant/bin", .{home}); diff --git a/src/utils.c b/src/utils.c index 0571a57..92287dd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -58,6 +58,19 @@ static int ant_join_app_path( return (written < 0 || (size_t)written >= out_size) ? -1 : 0; } +static int ant_legacy_home_path(char *out, size_t out_size, const char *suffix) { + const char *home = ant_home_dir(); + if (!home) return -1; + return ant_join_app_path(out, out_size, home, ".ant", suffix); +} + +static bool ant_legacy_home_exists(void) { + char path[4096]; + if (ant_legacy_home_path(path, sizeof(path), NULL) != 0) return false; + struct stat st; + return stat(path, &st) == 0; +} + static int ant_xdg_path( char *out, size_t out_size, const char *env_name, @@ -69,6 +82,10 @@ static int ant_xdg_path( if (!home) return -1; return ant_join_app_path(out, out_size, home, ".ant", suffix); #else + if (ant_legacy_home_exists()) { + return ant_legacy_home_path(out, out_size, suffix); + } + const char *base = ant_absolute_env(env_name); if (base) return ant_join_app_path(out, out_size, base, "ant", suffix); @@ -126,6 +143,9 @@ int ant_user_bin_path(char *out, size_t out_size) { #ifdef _WIN32 int written = snprintf(out, out_size, "%s/.ant/bin", home); #else + if (ant_legacy_home_exists()) { + return ant_legacy_home_path(out, out_size, "bin"); + } int written = snprintf(out, out_size, "%s/.local/bin", home); #endif return (written < 0 || (size_t)written >= out_size) ? -1 : 0;