From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id IILTDEQfG1+0EAAA0tVLHw (envelope-from ) for ; Fri, 24 Jul 2020 17:49:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id IOSxCEQfG18vNgAAB5/wlQ (envelope-from ) for ; Fri, 24 Jul 2020 17:49:56 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 966A8940538 for ; Fri, 24 Jul 2020 17:49:55 +0000 (UTC) Received: from localhost ([::1]:37350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jz1pS-0001K1-JI for larch@yhetil.org; Fri, 24 Jul 2020 13:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jz1p5-0001JV-Pc for emacs-orgmode@gnu.org; Fri, 24 Jul 2020 13:49:31 -0400 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]:45415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jz1p4-0004QS-31 for emacs-orgmode@gnu.org; Fri, 24 Jul 2020 13:49:31 -0400 Received: by mail-lj1-x22b.google.com with SMTP id r19so10780185ljn.12 for ; Fri, 24 Jul 2020 10:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:message-id:date:mime-version; bh=aAHrBv7KGYN+8Smlj8a5mtz3vwbFOe5ZyeUUvkbW4LQ=; b=UbXCFDfRyoGD5GoFhbGR1PViz9Z9ifBR725QAuHW4eomOuCDbTvKaVcKMcd/bqHMYu +csMnPm5bzbxWv6M32/GfuRqCDuUvZ9rklVv6b+bF0ctwQ8SMl7DFVgN/f0zKj+nper9 u3mQF7pVnAInNFirEJEiaoUAFLq8IVBREJ0AjrMBuqmZ3SqvW0UG7B2sfs8MrDCPHkAH Grxvfp9cdMk6aMBxyAAFk9gTg2Lj80iasKTgXoVo1RQ1z4sQDgQJRuPNMjJASmL1TBVq Sk5mp32j4HrgOsDjsxA3Cr3GFAQN/n1Voagf8GtFOOT87tsSj4cDVx9WANdj/VFT+o3+ sOOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:message-id:date :mime-version; bh=aAHrBv7KGYN+8Smlj8a5mtz3vwbFOe5ZyeUUvkbW4LQ=; b=PiiaW0sMB+05AUefoPTx1k5M1iNV+0u4Ul8feS6QKkXyh+mvikdIRS3ZsxUI4NcFuP zN1CtLZQDz+hlzN8aWnRgOm1gvsqgbZ0jzhUCfYJtZ/183J6w4usGUINZO1DbSHPkxi4 HW69/3v7RUwqNwlJ8D1+HyDFlDtmqON3sshAKSQAI39RNhZSbIOGdqWvI76Cf0pPXbex QNFRwKWpap0JZ1i2pwRNEdxPSBJ3aUj25qsteeSAuIAIzbY1cf7SAb+ZAnPNfKqFOgJL T6mP1APoQ9dtWYzXZMdkFfr8vXbvDAbk8Nu8z3TX+7M5eJ0FbKF6vO7FtiwPZSgRvDxB Vi4w== X-Gm-Message-State: AOAM533IoHXQHhS2VTKAVVsG5KuNGxBSd0uyB2KyfTOdeZ3IM+Te3eTg ExhYcSbya/BpjQnz3ijKOKr1OEvh X-Google-Smtp-Source: ABdhPJwJ+tmjc6PcVtrG4inYWzRzASOiTOIYzro4m7QaYkYZ5LEMvE1CdUcKErEY41ZSN1WoUbAkKg== X-Received: by 2002:a2e:9042:: with SMTP id n2mr4573783ljg.208.1595612967226; Fri, 24 Jul 2020 10:49:27 -0700 (PDT) Received: from arch ([98.128.186.110]) by smtp.gmail.com with ESMTPSA id e22sm390442ljb.12.2020.07.24.10.49.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 10:49:26 -0700 (PDT) User-agent: mu4e 1.4.10; emacs 26.3 From: John Herrlin To: emacs-orgmode@gnu.org Subject: file-mode source code block header argument Message-ID: <87h7twls64.fsf@gmail.com> Date: Fri, 24 Jul 2020 19:49:24 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::22b; envelope-from=jherrlin@gmail.com; helo=mail-lj1-x22b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=UbXCFDfR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.71 X-TUID: g82VirS8U1tw --=-=-= Content-Type: text/plain Hey, I am looking for a way to set permission on a file created from source code block result when :file header argument is used. I was looking for something like :tangle-mode but could not find anything. I wrote a patch that does just that and it works for my small use case. It's a header argument called :file-mode and can be used in the same way as :tangle-mode. Example usage: #+BEGIN_SRC shell :results file :file script.sh :file-mode (identity #o755) echo "#!/bin/bash" echo "echo Hello World" #+END_SRC Is this a suitable way of doing it? Best regards John --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-ob-core-file-mode-option-in-source-code-block-argume.patch Content-Transfer-Encoding: quoted-printable >From a58d960092ad944e17e9b22f337379ed90638b65 Mon Sep 17 00:00:00 2001 From: John Herrlin Date: Fri, 24 Jul 2020 13:45:18 +0200 Subject: [PATCH] ob-core: file-mode option in source code block arguments * ob-core.el (org-babel-execute-src-block): Source code block header argument :file-mode can set file permission if :file argument is provided --- doc/org-manual.org | 12 ++++++++++++ lisp/ob-core.el | 5 ++++- testing/lisp/test-ob.el | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index b616446..2919139 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17440,6 +17440,18 @@ default behavior is to automatically determine the= result type. uses the generated file name for both the "link" and "description" parts of the link. =20 + #+cindex: @samp{file-mode}, header argument + The =3Dfile-mode=3D header argument defines the file permission. For + example, to make a read-only file, use =E2=80=98:file-mode (identity + #o444)=E2=80=99. To make it executable, use =E2=80=98:file-mode (identit= y #o755)=E2=80=99 + + #+begin_example + ,#+BEGIN_SRC shell :results file :file script.sh :file-mode (identity #o= 755) + echo "#!/bin/bash" + echo "echo Hello World" + ,#+END_SRC + #+end_example + #+cindex: @samp{sep}, header argument By default, Org assumes that a table written to a file has TAB-delimited output. You can choose a different separator with diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e798595..cc3e002 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -731,7 +731,10 @@ block." (with-temp-file file (insert (org-babel-format-result result - (cdr (assq :sep params)))))) + (cdr (assq :sep params))))) + ;; Set permissions if header argument `:file-mode' is provided + (when (assq :file-mode params) + (set-file-modes file (cdr (assq :file-mode params))))) (setq result file)) ;; Possibly perform post process provided its ;; appropriate. Dynamically bind "*this*" to the diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 7c44622..c4aaad1 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1746,6 +1746,23 @@ line 1 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t)))))) )) =20 +(ert-deftest test-ob/file-mode () + "Ensure that file have correct permissions." + (let* ((file (org-babel-temp-file "file-mode-" ".sh")) + (filename (file-name-nondirectory file)) + (path (file-name-directory file))) + (org-test-with-temp-text + (concat + "#+BEGIN_SRC emacs-lisp :results file " + ":file " filename " " + ":output-dir " path " " + ":file-mode (identity #o755) + nil + #+END_SRC") + (org-babel-execute-src-block)) + (should (equal (file-modes file) + 493)))) + (ert-deftest test-ob-core/dir-mkdirp () "Test :mkdirp with :dir header combination." (should-not --=20 2.27.0 --=-=-=--