Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
walterl committed Mar 14, 2021
2 parents f071d0e + 9200637 commit b49b5e0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject updog "0.2.0"
(defproject updog "0.2.1-SNAPSHOT"
:description "Your watchdog for updates of software without updates."
:url "https://github.com/walterl/updog"
:license {:name "GPLv3"
Expand Down
6 changes: 4 additions & 2 deletions src/updog/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[["-d" "--db APPSDB" "EDN apps database to use."
:default "appsdb.edn"
:validate [fs/exists? "Apps database file not found."]]
["-L" "--long-log" "Use longer log output format."]
["-v" "--verbose" "Enable verbose output (set log level to debug)."]
["-h" "--help" "Display help text and exit."]] )

Expand Down Expand Up @@ -256,6 +257,7 @@
{:output (usage cmd)}

:else
(run-command! {:db-file (:db options)
:log-level (if (:verbose options) :debug :info)}
(run-command! {:db-file (:db options)
:log-level (if (:verbose options) :debug :info)
:log-format (when (:long-log options) :long)}
cmd cmd-opts))))
8 changes: 5 additions & 3 deletions src/updog/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

(defn init
"Initialize the application integrant system, using app `db-file`."
[{:keys [db-file log-level]}]
[{:keys [db-file log-level log-format]}]
(let [config (cond-> (-> (io/resource "system_config.edn") slurp ig/read-string)
db-file (assoc-in [:updog.apps-db.edn-db/apps-db :filename] db-file)
log-level (assoc-in [:updog.logging/timbre-logger :log-level] log-level))]
db-file (assoc-in [:updog.apps-db.edn-db/apps-db :filename] db-file)
log-level (assoc-in [:updog.logging/timbre-logger :log-level] log-level)
log-format (assoc-in [:updog.logging/timbre-logger :use-default-output-fn?]
(= log-format :long)))]
(ig/load-namespaces config)
(-> config
ig/prep
Expand Down
30 changes: 17 additions & 13 deletions src/updog/updater.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
[updog.unpack :as unpack]
[updog.util :as u]))

(defn- newer-version?
"Is version `a` newer than `b`? Always returns `true` if `b` is nil."
[a b]
(or (nil? b)
(pos? (compare a b))))

(defn- has-latest-version?
[{:keys [latest-version]}]
(and latest-version (:version latest-version)))
Expand All @@ -33,12 +27,22 @@
(cond
(not (fs/exists? dest-path))
(do
(log/debugf "File not found: %s" dest-path)
(log/debugf "App %s file not found: %s" app-name dest-path)
true)

;; Don't know what version we have; download the latest to be safe
(not last-version)
(do
(log/debugf "No last version for app %s. Updating to %s" app-name latest-version)
true)

(newer-version? latest-version last-version)
;; If the latest published version is different than the one we have, we
;; should probably change to it, regardless of whether it's semantically
;; newer or not. This is to account for accidental or retracted releases.
;; I.e. trust what upstream says is the latest, and use that.
(not= last-version latest-version)
(do
(log/debugf "App %s %s has newer version: %s"
(log/debugf "App %s %s will be updated to version: %s"
app-name last-version latest-version)
true)

Expand Down Expand Up @@ -104,10 +108,10 @@
(selected-apps app-key))]
(try
(update-file (assoc app
:app-key app-key
:tmp-dir base-tmp-dir
:db db
:source (source-of-type sources (:source-type app))))
:app-key app-key
:tmp-dir base-tmp-dir
:db db
:source (source-of-type sources (:source-type app))))
(catch Throwable ex
(log/errorf ex "Failed to update app %s" app-key)))))))

Expand Down

0 comments on commit b49b5e0

Please sign in to comment.