From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id CFmtHoFWOWMhWgEAbAwnHQ (envelope-from ) for ; Sun, 02 Oct 2022 11:14:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id SOWMHYFWOWPJTQAAG6o9tA (envelope-from ) for ; Sun, 02 Oct 2022 11:14:41 +0200 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 05BE0A0C1 for ; Sun, 2 Oct 2022 11:14:41 +0200 (CEST) Received: from localhost ([::1]:59304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oev3Y-00084E-7B for larch@yhetil.org; Sun, 02 Oct 2022 05:14:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oev2H-000840-ER for emacs-orgmode@gnu.org; Sun, 02 Oct 2022 05:13:22 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:41948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oev2E-0001JP-L6 for emacs-orgmode@gnu.org; Sun, 02 Oct 2022 05:13:20 -0400 Received: by mail-pj1-x1032.google.com with SMTP id x32-20020a17090a38a300b00209dced49cfso5096324pjb.0 for ; Sun, 02 Oct 2022 02:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date; bh=5STwst5ZX/2015JuWiUCiblKOza+1fP36jeWAglYWDM=; b=Z4xbzJIlBjFEpFtOkr3qelkzhN/k67Si0aicACEZ3+NXDee8DwzwfgdRlFNfFedNAk DICQOHFwKAiEEmXKSYSx4oK5H9djxPqMcgnBgAIfae2vaKlB+qXAHLzYXeMuQmQETBL4 XDq3+zJYrQajl3aXb+lld+a31jyNyMRRkYNlnwK7J0TeQgqUJKO5YOiOxh/SNwl3hLuh 52WPihZJXyemAZYtG1X1oBaXfsh6JHZsoxQ3dYNDCYV8KJieXEkxIDlppSet2ENCil8z 9pK/5XVjtK7x9VazrvdD2bi2lFN9D+JQG4/rea0kK9eRqCOrGH0mZVxl4aBRPlie4H98 +60w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=5STwst5ZX/2015JuWiUCiblKOza+1fP36jeWAglYWDM=; b=JV1ufSGKJ3YdK0dxzr76dPhT10k/FKJDCdPL6igKmSbUIqts4sIihmgm90D3OoxF75 vTVT5yO03YiI0CkZ4UAnxPUYb+VlJEmXCPu95n+vTUQWqx14H/572lE7Ic8l/jtKaarF b3sLXUfHYcgpiFpV0rYPdCOcs0CTAIYO7cOkKFBKUIqDPoHsOvCg1Nu75jfyHjVHC9hz 9vzphxt2cmSfLsy+UlJItrk14j5Jho1AVq/5OYQbVFxZPTkF7ebf8fjObKpYLgZH9Qey m31MHuyCIeTDxj5Q/9EGkcVrI9UrD3NyBWGUtpWplOgl10GfKnX9l6d4R08v2WD5NZB3 fB/w== X-Gm-Message-State: ACrzQf10poaUJYj3YK7VnMKOYrwdOd1l3tupIhpLuML8qB9ZXsrpvCyw S9mS/5GbEulonbVJrZk92no= X-Google-Smtp-Source: AMsMyM5wxOovwYWLEdPrsmgmKmlONRU7XkpK9ndMKfj0NhF6Wtier0QimIdYm5qbqumIMPaYesdojg== X-Received: by 2002:a17:903:2594:b0:17c:6117:2434 with SMTP id jb20-20020a170903259400b0017c61172434mr11589314plb.135.1664701996545; Sun, 02 Oct 2022 02:13:16 -0700 (PDT) Received: from localhost ([2409:8970:a80:3a4:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id c15-20020aa7952f000000b005609d3d3008sm1281243pfp.171.2022.10.02.02.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 02:13:14 -0700 (PDT) From: Ihor Radchenko To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: [PATCH v4] [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] In-Reply-To: <87bksn1nl1.fsf@localhost> References: <87k084v1wa.fsf@localhost> <871qtxhsm6.fsf@localhost> <87a68ce32u.fsf@localhost> <871qtodygs.fsf@localhost> <87v8qz9zui.fsf@localhost> <35cbf452-c3ed-d97f-db96-dcae57463eff@gmail.com> <87wnbc7ltm.fsf@localhost> <87bksn1nl1.fsf@localhost> Date: Sun, 02 Oct 2022 17:14:07 +0800 Message-ID: <87sfk6zixs.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1664702081; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=5STwst5ZX/2015JuWiUCiblKOza+1fP36jeWAglYWDM=; b=cwRWMb7GgWJzLtOyU+sNLgpNt4OvZQ5a8CzANo2HG8x7M4y62rNfh87L9t0NiKrKYXhw7I MVewaTnlCyrSP15HtFl9KzC0ja0+77KghuJbbXh91PdZ7gzlQD4y1wl61/CCJ9N/Rrrrri P/l75AVCi0EA1O6UOISAUGJqShZmLK5tSIvx2bWujgUjRlYlGPVsQ61CIJzh1XbQ2Xz+TC 3fyJpuIBRN7pXYfawlapep1rOEdXFgIb8NQ/vvuVCC7WNSGvCbZy8iz+mNrES5huSGFjdt GUd6+VLJiHRj/OyvGjH8JZOS3LlE5TpmnXmsBVKFNv/Fx6fO8lcjM1URvwa3LA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664702081; a=rsa-sha256; cv=none; b=iFxChxDcFyWMCJLbLZSge0xPFjpp/RtvHTg4NZz16AO3aWRBAoD/u3wII3FiJjOC3bYexq STN7bRo2w+UzL1ded+o4R3Xxs9d60wLkvqjLul2EqQV671IgS9/oi9MIUr4CHER6FXG0n4 AYFf1rQFgtlld9g98iP0xq53EL7VXa2zMruw4t9Ozaikby+Cd/CJV2y2JUJI5N4agMqayV NJnps3zZ6KnpgH/zCNCeh7dntg1T/AfaN6uCHDRVX/myrXV5OM8WX5ZEhZhNmnDVTknYiT f8WZbuurCQZZpW2svpTHCC7+VZ1awqi3/EBC6hd7cHKVs9Pnui58gvaiPqd8sg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Z4xbzJIl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.84 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Z4xbzJIl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 05BE0A0C1 X-Spam-Score: -1.84 X-Migadu-Scanner: scn1.migadu.com X-TUID: rXJs9cXihidW --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Max Nikulin writes: > >>> I do not think that it is a good idea. We currently promise to use the >>> first function in the list to generate the IDs. Other functions are >>> mostly a fallback to catch the existing attach dirs created in the past >>> using different ID scheme. >> >> My idea is to add an extra check that filters out nil values. I do not >> mind to signal a user error if first entry from >> `org-attach-id-to-path-function-list' returns nil and paths returned by >> other function do not exist. > > This would be possible, in addition to the patch above. > Or do you mean the default ts/uuid format functions to return nil to > short IDs as well? The new version of the patch allows all but first function return nil. See the attached. Let me know if there are any other objections. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v4-0001-org-attach-dir-from-id-Do-not-rely-on-ID-being-ov.patch >From ac88b8ac1117007eca49a0b229d8cee6cba8bc87 Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Sat, 23 Jul 2022 13:13:24 +0800 Subject: [PATCH v4] org-attach-dir-from-id: Do not rely on ID being over 6 chars long * lisp/org-attach.el (org-attach-id-uuid-folder-format): Fall back to "__/ID" when the ID contains 2 chars or less and cannot be split into the "xy/z...." path. (org-attach-id-ts-folder-format): Fall back to "______/ID" path format when the ID contains less than 7 chars and cannot be split into the "YYYYMM/rest" path. (org-attach-dir-from-id): Allow all but first function return nil and be ignored. (org-attach-id-to-path-function-list): Document that all but first function can return nil. Fixes https://orgmode.org/list/KC8PcypJapBpJQtJxM0kX5N7Z0THL2Lq6EQjBMzpw1-vgQf72egZ2JOIlTbPYiqAVD4MdSBhrhBZr2Ykf5DN1mocm1ANvvuKKZShlkgzKYM=@pm.me --- lisp/org-attach.el | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index 8509a6564..e4511794f 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -162,19 +162,27 @@ (defcustom org-attach-archive-delete nil (defun org-attach-id-uuid-folder-format (id) "Translate an UUID ID into a folder-path. Default format for how Org translates ID properties to a path for -attachments. Useful if ID is generated with UUID." - (format "%s/%s" - (substring id 0 2) - (substring id 2))) +attachments. Useful if ID is generated with UUID. + +When ID is too short (less than 3 chars), return \"__/ID\"." + (if (< (length id) 3) + (format "__/%s" id) + (format "%s/%s" + (substring id 0 2) + (substring id 2)))) (defun org-attach-id-ts-folder-format (id) "Translate an ID based on a timestamp to a folder-path. Useful way of translation if ID is generated based on ISO8601 timestamp. Splits the attachment folder hierarchy into -year-month, the rest." - (format "%s/%s" - (substring id 0 6) - (substring id 6))) +year-month, the rest. + +When ID is too short (less than 7 chars), return \"______/ID\"." + (if (< (length id) 7) + (format "______/%s" id) + (format "%s/%s" + (substring id 0 6) + (substring id 6)))) (defcustom org-attach-id-to-path-function-list '(org-attach-id-uuid-folder-format org-attach-id-ts-folder-format) @@ -182,7 +190,12 @@ (defcustom org-attach-id-to-path-function-list '(org-attach-id-uuid-folder-forma The first function in this list defines the preferred function which will be used when creating new attachment folders. All functions of this list will be tried when looking for existing -attachment folders based on ID." +attachment folders based on ID. + +The functions must either return string or nil. If a function returns +nil, its return value will be ignored when looking for existing +attachment folders. The first function in the list must always return +string." :group 'org-attach :package-version '(Org . "9.3") :type '(repeat (function :tag "Function with ID as input"))) @@ -400,11 +413,15 @@ (defun org-attach-dir-from-id (id &optional try-all) (expand-file-name org-attach-id-dir)))) (if try-all (let ((attach-dir attach-dir-preferred) - (fun-list (cdr org-attach-id-to-path-function-list))) + (fun-list (cdr org-attach-id-to-path-function-list)) + rtn) (while (and fun-list (not (file-directory-p attach-dir))) - (setq attach-dir (expand-file-name - (funcall (car fun-list) id) - (expand-file-name org-attach-id-dir))) + (setq rtn (funcall (car fun-list) id)) + ;; Skip nil return values. + (when rtn + (setq attach-dir (expand-file-name + rtn + (expand-file-name org-attach-id-dir)))) (setq fun-list (cdr fun-list))) (if (file-directory-p attach-dir) attach-dir -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92 --=-=-=--