Skip to content

Commit 5bdd6dc

Browse files
authored
Merge pull request #157 from VUP-Linux/feat/migrate-to-2025.06-odin
refactor: batch operations and migrate to Odin 2026.05 APIs
2 parents 63149c0 + 7fd769d commit 5bdd6dc

13 files changed

Lines changed: 328 additions & 223 deletions

File tree

vuru/src/commands/install.odin

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -41,90 +41,81 @@ install_run :: proc(args: []string, config: ^Config) -> int {
4141
return 1
4242
}
4343

44-
exit_code := 0
45-
46-
for pkg_name in args {
47-
// Resolve dependencies
48-
res, ok := resolve.resolve_deps(pkg_name, &idx, config.force_build)
49-
if !ok {
50-
// Print detailed errors if available
51-
if len(res.errors) > 0 {
52-
for err in res.errors {
53-
errors.print_error(err)
54-
}
55-
} else {
56-
errors.log_error("Failed to resolve dependencies for %s", pkg_name)
44+
// Resolve dependencies for all packages at once
45+
res, res_ok := resolve.resolve_deps(args, &idx, config.force_build)
46+
if !res_ok {
47+
if len(res.errors) > 0 {
48+
for err in res.errors {
49+
errors.print_error(err)
5750
}
58-
exit_code = 1
59-
continue
51+
} else {
52+
errors.log_error("Failed to resolve dependencies")
6053
}
54+
return 1
55+
}
6156

62-
// Check for missing packages
63-
if len(res.missing) > 0 {
64-
// Use detailed errors if available
65-
if len(res.errors) > 0 {
66-
for err in res.errors {
67-
errors.print_error(err)
68-
}
69-
} else {
70-
errors.log_error(
71-
"Cannot resolve: %s",
72-
strings.join(res.missing[:], ", ", context.temp_allocator),
73-
)
57+
// Check for missing packages
58+
if len(res.missing) > 0 {
59+
if len(res.errors) > 0 {
60+
for err in res.errors {
61+
errors.print_error(err)
7462
}
75-
exit_code = 1
76-
continue
63+
} else {
64+
errors.log_error(
65+
"Cannot resolve: %s",
66+
strings.join(res.missing[:], ", ", context.temp_allocator),
67+
)
7768
}
69+
return 1
70+
}
7871

79-
// Dry run - just show what would happen
80-
if config.dry_run {
81-
resolve.resolution_print(&res)
82-
continue
83-
}
72+
// Dry run - just show what would happen
73+
if config.dry_run {
74+
resolve.resolution_print(&res)
75+
return 0
76+
}
8477

85-
// Create transaction
86-
tx := transaction.transaction_from_resolution(&res)
78+
// Create transaction
79+
tx := transaction.transaction_from_resolution(&res)
8780

88-
transaction.transaction_print(&tx)
81+
transaction.transaction_print(&tx)
8982

90-
// Confirm unless -y
91-
if !config.yes && !transaction.transaction_confirm(&tx) {
92-
errors.log_info("Installation cancelled")
93-
continue
94-
}
83+
// Confirm unless -y
84+
if !config.yes && !transaction.transaction_confirm(&tx) {
85+
errors.log_info("Installation cancelled")
86+
return 0
87+
}
9588

96-
// Get build config if needed
97-
build_cfg: builder.Build_Config
98-
has_build := false
99-
for item in tx.items {
100-
if item.op == .Build_Install {
101-
has_build = true
102-
break
103-
}
89+
// Get build config if needed
90+
build_cfg: builder.Build_Config
91+
has_build := false
92+
for item in tx.items {
93+
if item.op == .Build_Install {
94+
has_build = true
95+
break
10496
}
97+
}
10598

106-
if has_build {
107-
cfg_result, cfg_ok := builder.default_build_config()
108-
if !cfg_ok {
109-
errors.log_error("VUP repository not found. Run 'vuru clone' first.")
110-
exit_code = 1
111-
continue
112-
}
113-
build_cfg = cfg_result
99+
if has_build {
100+
cfg_result, cfg_ok := builder.default_build_config()
101+
if !cfg_ok {
102+
errors.log_error("VUP repository not found. Run 'vuru clone' first.")
103+
return 1
114104
}
105+
build_cfg = cfg_result
106+
}
115107

116-
// Execute
117-
if !transaction.transaction_execute(&tx, &build_cfg, config.yes) {
118-
exit_code = 1
119-
}
108+
// Execute
109+
if !transaction.transaction_execute(&tx, &build_cfg, config.yes) {
110+
return 1
120111
}
121112

122-
return exit_code
113+
return 0
123114
}
124115

125116
// System upgrade (xbps-install -u)
126117
install_update :: proc(config: ^Config) -> int {
127-
cmd := make([dynamic]string, context.temp_allocator)
118+
cmd: [dynamic; 16]string
128119
append(&cmd, "sudo", "xbps-install", "-u")
129120

130121
if config.dry_run {

vuru/src/commands/query.odin

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ query_list :: proc(config: ^Config) -> int {
5858

5959
// Find package owning a file (xbps-query -o)
6060
query_ownedby :: proc(file: string, config: ^Config) -> int {
61-
cmd := make([dynamic]string, context.temp_allocator)
61+
cmd: [dynamic; 8]string
6262
append(&cmd, "xbps-query", "-o", file)
6363
if len(config.rootdir) > 0 {
6464
append(&cmd, "-r", config.rootdir)
@@ -68,7 +68,7 @@ query_ownedby :: proc(file: string, config: ^Config) -> int {
6868

6969
// Show package files (xbps-query -f)
7070
query_files :: proc(pkg: string, config: ^Config) -> int {
71-
cmd := make([dynamic]string, context.temp_allocator)
71+
cmd: [dynamic; 8]string
7272
append(&cmd, "xbps-query", "-f", pkg)
7373
if len(config.rootdir) > 0 {
7474
append(&cmd, "-r", config.rootdir)
@@ -78,7 +78,7 @@ query_files :: proc(pkg: string, config: ^Config) -> int {
7878

7979
// Show package dependencies (xbps-query -x)
8080
query_deps :: proc(pkg: string, config: ^Config) -> int {
81-
cmd := make([dynamic]string, context.temp_allocator)
81+
cmd: [dynamic; 8]string
8282
append(&cmd, "xbps-query", "-x", pkg)
8383
if config.recursive {
8484
append(&cmd, "--fulldeptree")
@@ -167,7 +167,7 @@ query_info :: proc(args: []string, config: ^Config) -> int {
167167
fmt.println()
168168
} else if !config.vup_only {
169169
// Check official repos
170-
cmd := make([dynamic]string, context.temp_allocator)
170+
cmd: [dynamic; 8]string
171171
append(&cmd, "xbps-query", "-R", pkg_name)
172172
if len(config.rootdir) > 0 {
173173
append(&cmd, "-r", config.rootdir)

vuru/src/commands/remove.odin

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package commands
22

3+
import "core:fmt"
4+
import "core:strings"
5+
36
import errors "../core/errors"
47
import xbps "../core/xbps"
58
import utils "../utils"
6-
import "core:fmt"
79

810
// Remove command implementation
911
remove_run :: proc(args: []string, config: ^Config) -> int {
@@ -25,52 +27,53 @@ remove_run :: proc(args: []string, config: ^Config) -> int {
2527
return 1
2628
}
2729

28-
exit_code := 0
29-
for pkg in args {
30-
if xbps_uninstall(pkg, config) != 0 {
31-
exit_code = 1
32-
}
33-
}
34-
35-
return exit_code
36-
}
37-
38-
// Remove orphan packages (xbps-remove -o)
39-
remove_orphans :: proc(config: ^Config) -> int {
40-
cmd := make([dynamic]string, context.temp_allocator)
30+
cmd: [dynamic; 64]string
4131

42-
// Need sudo for system operations (unless dry-run)
4332
if !config.dry_run {
4433
append(&cmd, "sudo")
4534
}
46-
append(&cmd, "xbps-remove", "-o")
35+
append(&cmd, "xbps-remove")
4736

4837
if config.dry_run {
4938
append(&cmd, "-n")
5039
}
5140
if config.yes {
5241
append(&cmd, "-y")
5342
}
43+
if config.recursive {
44+
append(&cmd, "-R")
45+
}
5446
if config.verbose {
5547
append(&cmd, "-v")
5648
}
5749
if len(config.rootdir) > 0 {
5850
append(&cmd, "-r", config.rootdir)
5951
}
6052

61-
errors.log_info("Removing orphan packages...")
62-
return xbps.remove_orphans(config.yes, utils.run_command)
53+
for pkg in args {
54+
append(&cmd, pkg)
55+
}
56+
57+
errors.log_info("Removing %s...", strings.join(args[:], ", ", context.temp_allocator))
58+
59+
if utils.run_command(cmd[:]) == 0 {
60+
errors.log_info("Successfully removed package(s)")
61+
return 0
62+
}
63+
64+
errors.log_error("xbps-remove failed")
65+
return 1
6366
}
6467

65-
// Clean package cache (xbps-remove -O)
66-
remove_cache :: proc(config: ^Config) -> int {
67-
cmd := make([dynamic]string, context.temp_allocator)
68+
// Remove orphan packages (xbps-remove -o)
69+
remove_orphans :: proc(config: ^Config) -> int {
70+
cmd: [dynamic; 16]string
6871

69-
// Need sudo for cache operations (unless dry-run)
72+
// Need sudo for system operations (unless dry-run)
7073
if !config.dry_run {
7174
append(&cmd, "sudo")
7275
}
73-
append(&cmd, "xbps-remove", "-O")
76+
append(&cmd, "xbps-remove", "-o")
7477

7578
if config.dry_run {
7679
append(&cmd, "-n")
@@ -85,48 +88,33 @@ remove_cache :: proc(config: ^Config) -> int {
8588
append(&cmd, "-r", config.rootdir)
8689
}
8790

88-
errors.log_info("Cleaning package cache...")
89-
return xbps.clean_cache(utils.run_command)
91+
errors.log_info("Removing orphan packages...")
92+
return xbps.remove_orphans(config.yes, utils.run_command)
9093
}
9194

92-
// Remove a package using xbps-remove
93-
xbps_uninstall :: proc(pkg_name: string, config: ^Config) -> int {
94-
if len(pkg_name) == 0 {
95-
errors.log_error("Invalid package name")
96-
return -1
97-
}
98-
99-
errors.log_info("Removing %s...", pkg_name)
100-
101-
cmd := make([dynamic]string, context.temp_allocator)
95+
// Clean package cache (xbps-remove -O)
96+
remove_cache :: proc(config: ^Config) -> int {
97+
cmd: [dynamic; 16]string
10298

103-
// Need sudo for package removal (unless dry-run)
99+
// Need sudo for cache operations (unless dry-run)
104100
if !config.dry_run {
105101
append(&cmd, "sudo")
106102
}
107-
append(&cmd, "xbps-remove", pkg_name)
103+
append(&cmd, "xbps-remove", "-O")
108104

109105
if config.dry_run {
110106
append(&cmd, "-n")
111107
}
112108
if config.yes {
113109
append(&cmd, "-y")
114110
}
115-
if config.recursive {
116-
append(&cmd, "-R")
117-
}
118111
if config.verbose {
119112
append(&cmd, "-v")
120113
}
121114
if len(config.rootdir) > 0 {
122115
append(&cmd, "-r", config.rootdir)
123116
}
124117

125-
if utils.run_command(cmd[:]) == 0 {
126-
errors.log_info("Successfully removed %s", pkg_name)
127-
return 0
128-
}
129-
130-
errors.log_error("xbps-remove failed for %s", pkg_name)
131-
return -1
118+
errors.log_info("Cleaning package cache...")
119+
return xbps.clean_cache(utils.run_command)
132120
}

0 commit comments

Comments
 (0)