| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | import sync.pool |
| 5 | |
| 6 | pub struct OutdatedResult { |
| 7 | name string |
| 8 | mut: |
| 9 | outdated bool |
| 10 | } |
| 11 | |
| 12 | fn vpm_outdated() { |
| 13 | outdated := get_outdated() |
| 14 | if outdated.len > 0 { |
| 15 | println('Outdated modules:') |
| 16 | for m in outdated { |
| 17 | println(' ${m}') |
| 18 | } |
| 19 | } else { |
| 20 | println('Modules are up to date.') |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | fn get_outdated() []string { |
| 25 | installed := get_installed_modules() |
| 26 | if installed.len == 0 { |
| 27 | println('No modules installed.') |
| 28 | exit(0) |
| 29 | } |
| 30 | mut pp := pool.new_pool_processor( |
| 31 | callback: fn (mut pp pool.PoolProcessor, idx int, wid int) &OutdatedResult { |
| 32 | mut result := &OutdatedResult{ |
| 33 | name: pp.get_item[string](idx) |
| 34 | } |
| 35 | path := get_path_of_existing_module(result.name) or { return result } |
| 36 | result.outdated = is_outdated(path) |
| 37 | return result |
| 38 | } |
| 39 | ) |
| 40 | pp.work_on_items(installed) |
| 41 | mut outdated := []string{} |
| 42 | for res in pp.get_results[OutdatedResult]() { |
| 43 | if res.outdated { |
| 44 | outdated << res.name |
| 45 | } |
| 46 | } |
| 47 | return outdated |
| 48 | } |
| 49 | |
| 50 | fn is_outdated(path string) bool { |
| 51 | vcs := vcs_used_in_dir(path) or { return false } |
| 52 | args := vcs_info[vcs].args |
| 53 | mut outputs := []string{} |
| 54 | for step in args.outdated { |
| 55 | cmd := [vcs.str(), args.path, os.quoted_path(path), step].join(' ') |
| 56 | vpm_log(@FILE_LINE, @FN, 'cmd: ${cmd}') |
| 57 | res := os.execute(cmd) |
| 58 | vpm_log(@FILE_LINE, @FN, 'output: ${res.output}') |
| 59 | if res.exit_code != 0 { |
| 60 | return false |
| 61 | } |
| 62 | if vcs == .hg { |
| 63 | // HG uses only one outdated step. If it has not failed, the module is outdated. |
| 64 | return true |
| 65 | } |
| 66 | outputs << res.output |
| 67 | } |
| 68 | // Compare the current and latest origin commit sha. |
| 69 | return outputs[1] != outputs[2] |
| 70 | } |
| 71 | |