guix_mirror_bot pushed a commit to branch core-packages-team
in repository guix.

commit 355a24ad9a19af5bcdc18ecfb7f33821ffc3d4be
Author: Sergio Pastor Pérez <[email protected]>
AuthorDate: Tue Mar 17 11:02:07 2026 +0100

    utils: Add helpers to make files executable.
    
    * doc/guix.texi (Build Utilities, set-file-permissions): Document procedure.
    (make-file-executable): Document procedure.
    * guix/build/utils.scm (set-file-permissions): New procedure.
    (make-file-executable): Ne procedure.
    (make-file-writable): Implement using `set-file-permissions'
    (make-desktop-entry-file): Set executable permissions for destination 
desktop
    file.
    
    Change-Id: Ic4e5b3c30851c0d5cf262915aab190732b3b365b
---
 doc/guix.texi        |  8 ++++++++
 guix/build/utils.scm | 25 ++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 11138951c6..4d8e47375f 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -11640,10 +11640,18 @@ Create @var{directory} if it does not exist and copy 
@var{file} in there
 under the same name.
 @end deffn
 
+@deffn {Procedure} set-file-permissions file permissions
+Set the permissions of @var{file} to @var{permissions}.
+@end deffn
+
 @deffn {Procedure} make-file-writable file
 Make @var{file} writable for its owner.
 @end deffn
 
+@deffn {Procedure} make-file-executable file
+Make @var{file} executable.
+@end deffn
+
 @deffn {Procedure} copy-recursively source destination @
   [#:log (current-output-port)] [#:follow-symlinks? #f] @
   [#:copy-file copy-file] [#:keep-mtime? #f] [#:keep-permissions? #t] @
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 7003d8262f..1f93e0379a 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -10,6 +10,7 @@
 ;;; Copyright © 2021, 2022 Maxime Devos <[email protected]>
 ;;; Copyright © 2021 Brendan Tildesley <[email protected]>
 ;;; Copyright © 2023 Carlo Zancanaro <[email protected]>
+;;; Copyright © 2026 Sergio Pastor Pérez <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,7 +75,9 @@
             with-directory-excursion
             mkdir-p
             install-file
+            set-file-permissions
             make-file-writable
+            make-file-executable
             copy-recursively
             delete-file-recursively
             file-name-predicate
@@ -422,10 +425,18 @@ name."
   (mkdir-p directory)
   (copy-file file (string-append directory "/" (basename file))))
 
+(define (set-file-permissions file permissions)
+  "Set the permissions of FILE to PERMISSIONS."
+  (let ((stat (lstat file)))
+    (chmod file (logior permissions (stat:perms stat)))))
+
 (define (make-file-writable file)
   "Make FILE writable for its owner."
-  (let ((stat (lstat file)))                      ;XXX: symlinks
-    (chmod file (logior #o600 (stat:perms stat)))))
+  (set-file-permissions file #o600))
+
+(define (make-file-executable file)
+  "Make FILE executable."
+  (set-file-permissions file #o555))
 
 (define* (copy-recursively source destination
                            #:key
@@ -1650,7 +1661,15 @@ 
https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-lat
                         value))
              (_
               (parse key value)))
-           (loop (cddr args))))))))
+           (loop (cddr args)))))))
+  ;; Program launchers such as Plasma's expect desktop files to be either
+  ;; owned by root or executable, this is a security measure since any exec
+  ;; line in a desktop file essentially makes the file as dangerous as an
+  ;; executable file.
+  ;;
+  ;; For more information, read the discussion on:
+  ;; https://codeberg.org/guix/guix/issues/1578
+  (make-file-executable destination))
 
 
 ;;;

Reply via email to