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 UXd0MHGSJl/ABwAA0tVLHw (envelope-from ) for ; Sun, 02 Aug 2020 10:16:17 +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 UOnCK3GSJl/FHgAAB5/wlQ (envelope-from ) for ; Sun, 02 Aug 2020 10:16:17 +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 2473294053F for ; Sun, 2 Aug 2020 10:16:17 +0000 (UTC) Received: from localhost ([::1]:53940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k2B2O-0005lR-34 for larch@yhetil.org; Sun, 02 Aug 2020 06:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k2B21-0005ks-GF for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 06:15:53 -0400 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]:41503) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k2B1y-0002Ea-Lm for emacs-orgmode@gnu.org; Sun, 02 Aug 2020 06:15:53 -0400 Received: by mail-lj1-x230.google.com with SMTP id s16so21448345ljc.8 for ; Sun, 02 Aug 2020 03:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:message-id :date:mime-version; bh=Lmfec7n9MASEQTfOZgGiKu8+VblNJjdzx1lYleRpSd8=; b=VGG28BAlzV6Rmaihk2l495UKkkJg/HVTZRgY9BCRrMdynhowmwYl3VxWBNXsf95Bfr gPXn/Kivx/ys/zme+9fsieNNnW4Qbmb51F904g8cv2B/WCCTTqP+OodGGqxBKP98e/sI C4KP4P199FCTe/HxxP9OAGT8sf35IYmN5XFsg/2ptnjD1WgEoft4/MG2fh7gmdcnEX5s HQDIm88TgP4VSF7cccaIBWtKIDz0t4hhhYy4p7HJyGOn0Hr/VMiDawfF4WzlTaNiUTDO U+Pyo4C6sYb9dn/ZQwdcWkLiiw3AHfJqUXEV3ZL+TaKcOPz8ztwEQlPWe5lciz37wiou zp2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:message-id:date:mime-version; bh=Lmfec7n9MASEQTfOZgGiKu8+VblNJjdzx1lYleRpSd8=; b=FTr9gtDz16q/kNay0S1SPRlfOeb3VI3q5eS7I4A2eaKAYiKG5Q+jXiZCch86MOerOD zSRhB9SHOreuGKdBAMU3M8KJfgl+Lt2C9e4gok6dCcFtYD+/fCK2ZM9hdtcK5v5pUqcx SWaJvAS+4Lq+821zllqiJOT5vRIzPs5m48nCiPlnHQWScdNlitkrepJDH3pp3z6h1i5a zQ8xvBCcI26h32DFQVrkJa7JoE5cNRA2XQu6p1ATeCpeLW4t9ysfHUsujX0qSVpRUxKf E/UA6QZ/rzdpFznby0amxc5YV0eIwamzefxXeMBZ3HCdlf4DYaFqJOppfkzoDrTZxggT /lcQ== X-Gm-Message-State: AOAM5318Azn0I6+f35pUQufFszzO7L5F90LBDLDVNFKLtDX2BSBWiitz eW37Er4NOqabml9Gzq1P7QSjJpwi X-Google-Smtp-Source: ABdhPJyOlSbDz2usoIkhv7JGpEj98QdBTBpsiW6yeI/TUTmYYfLWxyZznguOiwgzi1pjI/Ltm4Xrqg== X-Received: by 2002:a2e:7203:: with SMTP id n3mr5209573ljc.174.1596363347338; Sun, 02 Aug 2020 03:15:47 -0700 (PDT) Received: from arch ([98.128.186.110]) by smtp.gmail.com with ESMTPSA id 14sm3442477lfr.17.2020.08.02.03.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 03:15:46 -0700 (PDT) References: <87h7twls64.fsf@gmail.com> <878sez9c1i.fsf@kyleam.com> User-agent: mu4e 1.4.10; emacs 26.3 From: John Herrlin To: Kyle Meyer Subject: Re: file-mode source code block header argument In-reply-to: <878sez9c1i.fsf@kyleam.com> Message-ID: <87ft95xsj4.fsf@gmail.com> Date: Sun, 02 Aug 2020 12:15:43 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::230; envelope-from=jherrlin@gmail.com; helo=mail-lj1-x230.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: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=no 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: , Cc: emacs-orgmode@gnu.org 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=VGG28BAl; 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: 3.29 X-TUID: q5HjHn0jbejY --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thank you for the comments Kyle! I updated the patch accordingly. Took your test straight of as I think it's really clean and easy to reason about. Best regards Kyle Meyer writes: > John Herrlin writes: > >> 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. > > Thanks for the patch. > >> 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 #o7= 55) >> echo "#!/bin/bash" >> echo "echo Hello World" >> #+END_SRC >> >> Is this a suitable way of doing it? > > Looks sensible to me. Hopefully others with more knowledge and interest > in Babel will chime in if they disagree. In the meantime, I mostly just > have convention nit-picks... > >> 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 > > Please end this sentence with a period. > > Also, assuming the listing at > https://orgmode.org/worg/org-contribute.html is up to date, this should > come with a TINYCHANGE cookie. > >> --- >> doc/org-manual.org | 12 ++++++++++++ >> lisp/ob-core.el | 5 ++++- >> testing/lisp/test-ob.el | 17 +++++++++++++++++ >> 3 files changed, 33 insertions(+), 1 deletion(-) > > Please also add an ORG-NEWS entry. > >> 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. >> >> + #+cindex: @samp{file-mode}, header argument >> + The =3Dfile-mode=3D header argument defines the file permission. For > > s/permission/permissions/ > > Also, the convention for this project is two spaces following a > sentence. > >> + 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 (iden= tity #o755)=E2=80=99 > > These =E2=80=98...=E2=80=99 should be =3D...=3D, I think. > > I know this text is just following the text for :tangle-mode, but from > my point of view, "For example ..." through to the example block could > be dropped. If the reader knows about file permissions, then it's > unnecessary; if they don't, I don't see how it'd be enough to help them > figure out what's going on. > >> + #+begin_example >> + ,#+BEGIN_SRC shell :results file :file script.sh :file-mode (identity= #o755) >> + echo "#!/bin/bash" >> + echo "echo Hello World" >> + ,#+END_SRC >> + #+end_example > >> 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 > > To continue my nit-picking: Please follow the style of the surrounding > comments, ending with a period and filling the paragraph. > >> + (when (assq :file-mode params) >> + (set-file-modes file (cdr (assq :file-mode params))))) > > Looks good. > >> (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)))))) >> )) >> >> +(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") > > Rather than using org-babel-temp-file to generate a temporary file, I > think the preferred way to do this would be to use > org-test-with-temp-text-in-file. > >> + (org-babel-execute-src-block)) >> + (should (equal (file-modes file) >> + 493)))) > > To my eyes, spelling this as #o755 would be clearer. > > So, perhaps something like this: > > (ert-deftest test-ob/file-mode () > "Ensure that file have correct permissions." > (should > (equal #o755 > (org-test-with-temp-text-in-file " > #+begin_src emacs-lisp :results file :file t.sh :file-mode (identity #o75= 5) > nil > #+end_src" > (org-babel-next-src-block) > (org-babel-execute-src-block) > (unwind-protect > (file-modes "t.sh") > (delete-file "t.sh")))))) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-core-file-mode-option-in-source-code-block-argume.patch >From 43ef5de5267b463b9656b7f5db37eafe62cb7f61 Mon Sep 17 00:00:00 2001 From: John Herrlin Date: Sun, 2 Aug 2020 10:39:02 +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 permissions if `:file' argument is provided. (org-babel-common-header-args-w-values): Add `:file-mode' to common header arguments. TINYCHANGE --- doc/org-manual.org | 11 +++++++++++ etc/ORG-NEWS | 5 +++++ lisp/ob-core.el | 7 ++++++- testing/lisp/test-ob.el | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 0f012d4..3eb745b 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17444,6 +17444,17 @@ default behavior is to automatically determine the result type. TAB-delimited output. You can choose a different separator with the =sep= header argument. + #+cindex: @samp{file-mode}, header argument + The =file-mode= header argument defines the file permissions. To + make it executable, use =:file-mode (identity #o755)=. + + #+begin_example + ,#+BEGIN_SRC shell :results file :file script.sh :file-mode (identity #o755) + echo "#!/bin/bash" + echo "echo Hello World" + ,#+END_SRC + #+end_example + *** Format :PROPERTIES: :UNNUMBERED: notoc diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 1ac7486..e754615 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -261,6 +261,11 @@ explicitly: In situations where ~org-return~ calls ~newline~, multiple newlines can now be inserted with this prefix argument. +*** New source code block header argument `:file-mode' + +Source code block header argument `:file-mode' can set file +permissions if `:file' argument is provided. + ** New commands *** ~org-table-header-line-mode~ diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e798595..adc5358 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -400,6 +400,7 @@ then run `org-babel-switch-to-session'." (file . :any) (file-desc . :any) (file-ext . :any) + (file-mode . ((#o755 #o555 #o444 :any))) (hlines . ((no yes))) (mkdirp . ((yes no))) (no-expand) @@ -731,7 +732,11 @@ block." (with-temp-file file (insert (org-babel-format-result result - (cdr (assq :sep params)))))) + (cdr (assq :sep params))))) + ;; Set file 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..03296ba 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -1746,6 +1746,20 @@ line 1 (cdr (assq :file (nth 2 (org-babel-get-src-block-info t)))))) )) +(ert-deftest test-ob/file-mode () + "Ensure that file have correct permissions." + (should + (equal #o755 + (org-test-with-temp-text-in-file " +#+begin_src emacs-lisp :results file :file t.sh :file-mode (identity #o755) +nil +#+end_src" + (org-babel-next-src-block) + (org-babel-execute-src-block) + (unwind-protect + (file-modes "t.sh") + (delete-file "t.sh")))))) + (ert-deftest test-ob-core/dir-mkdirp () "Test :mkdirp with :dir header combination." (should-not -- 2.28.0 --=-=-=--