~ruther/guix-local

3bb168b0997d2ba2ef15e8eef2890582c8a6df9c — Ludovic Courtès 10 years ago 65797bf
utils: Add 'switch-symlinks', moved from (guix ui).

* guix/ui.scm (switch-symlinks): Move to...
* guix/utils.scm: ... here.  New procedure.
* guix/scripts/pull.scm: Use it.
3 files changed, 9 insertions(+), 8 deletions(-)

M guix/scripts/pull.scm
M guix/ui.scm
M guix/utils.scm
M guix/scripts/pull.scm => guix/scripts/pull.scm +1 -0
@@ 18,6 18,7 @@

(define-module (guix scripts pull)
  #:use-module (guix ui)
  #:use-module (guix utils)
  #:use-module (guix scripts)
  #:use-module (guix store)
  #:use-module (guix config)

M guix/ui.scm => guix/ui.scm +0 -8
@@ 73,7 73,6 @@
            read/eval
            read/eval-package-expression
            location->string
            switch-symlinks
            config-directory
            fill-paragraph
            texi->plain-text


@@ 715,13 714,6 @@ replacement if PORT is not Unicode-capable."
    (($ <location> file line column)
     (format #f "~a:~a:~a" file line column))))

(define (switch-symlinks link target)
  "Atomically switch LINK, a symbolic link, to point to TARGET.  Works
both when LINK already exists and when it does not."
  (let ((pivot (string-append link ".new")))
    (symlink target pivot)
    (rename-file pivot link)))

(define (config-directory)
  "Return the name of the configuration directory, after making sure that it
exists.  Honor the XDG specs,

M guix/utils.scm => guix/utils.scm +8 -0
@@ 74,6 74,7 @@
            arguments-from-environment-variable
            file-extension
            file-sans-extension
            switch-symlinks
            call-with-temporary-output-file
            call-with-temporary-directory
            with-atomic-file-output


@@ 557,6 558,13 @@ minor version numbers from version-string."
        (substring file 0 dot)
        file)))

(define (switch-symlinks link target)
  "Atomically switch LINK, a symbolic link, to point to TARGET.  Works
both when LINK already exists and when it does not."
  (let ((pivot (string-append link ".new")))
    (symlink target pivot)
    (rename-file pivot link)))

(define* (string-replace-substring str substr replacement
                                   #:optional
                                   (start 0)