From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id yIjqI+/7JF88ZwAA0tVLHw (envelope-from ) for ; Sat, 01 Aug 2020 05:21:51 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id eMjCH+/7JF+vewAA1q6Kng (envelope-from ) for ; Sat, 01 Aug 2020 05:21:51 +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 985499403AB for ; Sat, 1 Aug 2020 05:21:50 +0000 (UTC) Received: from localhost ([::1]:47692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1jxt-0005pl-K1 for larch@yhetil.org; Sat, 01 Aug 2020 01:21:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1jxW-0005pO-OF for emacs-orgmode@gnu.org; Sat, 01 Aug 2020 01:21:26 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:58848) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1jxS-0003OE-5W for emacs-orgmode@gnu.org; Sat, 01 Aug 2020 01:21:26 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id AB979F467D; Sat, 1 Aug 2020 01:21:19 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:date:message-id:mime-version:content-type :content-transfer-encoding; s=sasl; bh=BY59CGapjCGg3ziqDRAhBxcK1 +E=; b=CUDR/yg3ENUbGbZQSI3lsk40iKR7MJ79jcFT17rQNtYu1p/qUtnv3kP/I xcf8MIjt0N8iUDFg7XGma/TNIuHdX+bMP/3sCeYFeBNqnPvHvg7VhKhX8Ov0RiEX VPBqoOO49LnywW+y/tzwcUlLklqLJH2b7bFnrOUATdKVZcbBGQ= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 854C7F467C; Sat, 1 Aug 2020 01:21:19 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:date:message-id:mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=crpAIgvS30S027Zeju3OIWC9ZYlwmdyePLrKmzj9pTc=; b=P6eDCYCE25xA5UYRRv5X9keJNLaI7LEs9Is5hGKKYI9fv72oGlyhDxuBAQJJRbovpjMTNbFkiu7TTIr5ohnVLzt8KAQyUPVREBNICeA6Czydykk5S7jJiYOdZtSEfhf6oo5O3paPC733N+9tUqh+ql6WUt8elBGJWDWJwnhp4hQ= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id A7A19F467B; Sat, 1 Aug 2020 01:21:16 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: John Herrlin Subject: Re: file-mode source code block header argument In-Reply-To: <87h7twls64.fsf@gmail.com> Date: Sat, 01 Aug 2020 01:21:13 -0400 Message-ID: <878sez9c1i.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: D3138AFE-D3B6-11EA-9477-843F439F7C89-24757444!pb-smtp21.pobox.com Received-SPF: pass client-ip=173.228.157.53; envelope-from=kyle@kyleam.com; helo=pb-smtp21.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/01 01:21:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: , 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=pobox.com header.s=sasl header.b=CUDR/yg3; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=P6eDCYCE; dmarc=none; 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.21 X-TUID: niYXK1DJDIyu 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 #o75= 5) > 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 t= he result type. > uses the generated file name for both the "link" and > "description" parts of the link. >=20=20 > + #+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 (ident= ity #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)))))) > )) >=20=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") 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 #o755) nil #+end_src" (org-babel-next-src-block) (org-babel-execute-src-block) (unwind-protect (file-modes "t.sh") (delete-file "t.sh"))))))