From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6E9XIJ2F22JYEAAAbAwnHQ (envelope-from ) for ; Sat, 23 Jul 2022 07:22:37 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id sLdjIJ2F22KXOQEA9RJhRA (envelope-from ) for ; Sat, 23 Jul 2022 07:22:37 +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 C020F39F70 for ; Sat, 23 Jul 2022 07:22:36 +0200 (CEST) Received: from localhost ([::1]:60590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oF7b1-0001jL-8E for larch@yhetil.org; Sat, 23 Jul 2022 01:22:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oF7aE-0001j9-OK for emacs-orgmode@gnu.org; Sat, 23 Jul 2022 01:21:47 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:37748) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oF7aB-0003pX-1F for emacs-orgmode@gnu.org; Sat, 23 Jul 2022 01:21:46 -0400 Received: by mail-pf1-x430.google.com with SMTP id w185so6049575pfb.4 for ; Fri, 22 Jul 2022 22:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=vKdkxgbCEeaFEn0XlWS1rVym6HxJJ26EVgWZ4FfQSuU=; b=SAgUIlawv6tiCFw3hD9rRPMDTIsTIkPG4B9pADX7YlqfiDeaVnk4cmPHjyEVyb2/1c kir0y4ADzsEWsOXgk4NWe/ZY6z2fkE8Mf5IEqohYb/aWIBE9Oi8NIgStY0fFc6lO2D0f eDmzBIM4IAVzOHBadW0UOXiyNqgCLUlZspcEhJhw1NfOhadczOjX1Up/kf004VlalSC/ pLCyQSL2AnoJXmcbvFuczp4DbhSt8Q3urxQ3lzs6K80wxs6leyzzorWSV+LZbVVN/f6S OyFhgWzXdKzlspzkn13VEi8c8nh3q/6IYjd4Rp4nSsvuHkYE1p7hR85fNF1kTAWzEWP/ n2fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=vKdkxgbCEeaFEn0XlWS1rVym6HxJJ26EVgWZ4FfQSuU=; b=aJ+8ClJE75GqcYEfmEQ8rKtLeIbEasnuvSWjbXH47WGNejTC2MTju8K8cJ1UqCMX2D wd2uYo9h8LD2TpL3fh3nFUl45OUYlGZ5sqyHeNfGeCcMS4rUGOHQ1zcsjPMlO5FXqJgv 3L57dTN2k54Ng+mWnQ1XwSp9V1sDa/BAMZV9/m8AmHmcMlXdbdwKM9iV8uo67eme5dvp oPLsh34k6YZJVugnSA8/EMleliqnOIBuk8Gs1UHhTtu4AdHlxHSTMS2XJ6iiwkKsKOpD BJm6YNLVNt+VsO2yYrzZiQ3bmrf28o6e9eaaMioEHC8hMmo7zj6LCjKzVtRkGuEYzeZH VZLg== X-Gm-Message-State: AJIora/z4SnGZaHQNwPMALKgEFts0gK7DJQsVH6L2ZiveGXteWQdci5B x+hX+YcNX12L2N1VHHNxDxU= X-Google-Smtp-Source: AGRyM1vAiqDJGzpjKbetDyyv8iI1AeCoQ3YxNKRn4VUSGSaEI/MSnM4AellSFfFcJBLpePKJ22PmnQ== X-Received: by 2002:a05:6a00:1908:b0:525:5dad:cb1c with SMTP id y8-20020a056a00190800b005255dadcb1cmr3252140pfi.47.1658553701036; Fri, 22 Jul 2022 22:21:41 -0700 (PDT) Received: from localhost ([1.83.155.1]) by smtp.gmail.com with ESMTPSA id b19-20020a62a113000000b0052ba88f2de0sm4852320pff.131.2022.07.22.22.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 22:21:40 -0700 (PDT) From: Ihor Radchenko To: Janek F Cc: "emacs-orgmode@gnu.org" Subject: [PATCH] Re: [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] In-Reply-To: References: Date: Sat, 23 Jul 2022 13:22:45 +0800 Message-ID: <87k084v1wa.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=yantar92@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, T_SCC_BODY_TEXT_LINE=-0.01 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-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1658553757; 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=vKdkxgbCEeaFEn0XlWS1rVym6HxJJ26EVgWZ4FfQSuU=; b=JsOCLZ4eCCfLvuGb6947zIYLmfGOtIpiZ8xXUEY5F4KtbfONAZ3c30lJTUBhowE2ZK5FcT Xmsem+uCLynWozaJOtF56zmpeJkHa8BKW/ai/Ct6t8CE0yLnkWPLCEK9CTJpWTLc55EdQF NVFcEv6t5O7LKggo2Qr/yIoTjtevIOYbxG4H4afzddL95KhdTNZvchyiWxSkGWvTmw6mqo ZUlw4OJw9K/jda/uBkaZcjkZXw4HWuEZLBSUnILm2Py2fb8mEmaaJXsgMDZRA2OwIBfGwR UJvW9xW1RTP57HephKW+VUyFZH+jPBasXJQJsJUrVkdcEs5iIs/twKAuD/JJsw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1658553757; a=rsa-sha256; cv=none; b=b8jlCUVQkxJ/21tPw7maUNT2K0j2GysWlqxx+pYvLTLKLca1fMaCur/oAf1SmQKOtHcBgB IaWJC7AehnCaaGaWz8ptB+Frz7/j2dNcePUeRGRcft0EQmAfi8dqkoV2jqDmvMnn+PGtTW 6b7Wjqxj/iZGLc3SCtuiIb2U5OUVrjtxRW+y1TPccNPi0qGLW4DnkSpDlXGUwzrWYFKPX2 ue19cc2L6RtW3vO5in+a5I15fZotQ0aaIh5P2VURYf4UP37oBpReTGwb6QWxI9wZclMPFo tCffjEanPy4mw9vfWtq2Llng7FGHtW0FWzYSe9CgCkmBlO91PaG9rCrjPnECkw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SAgUIlaw; 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: -3.44 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SAgUIlaw; 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: C020F39F70 X-Spam-Score: -3.44 X-Migadu-Scanner: scn1.migadu.com X-TUID: Mx6w9eMaqCMB --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Janek F writes: > When setting org-id-method to 'ts or 'org, > org-attach seems to use org-attach-id-ts-folder-format > to create its hierarchy. > > However I tend to customize IDs for important files by hand, > causing any attempt to use org-attach on that file to fail > if the ID is shorter than six characters: > > =C2=A0 =C2=A0 org-attach-id-ts-folder-format: Args out of range: "ftt", 0= , 6 > > This method should be adjusted to handle non-ts-ids just as well, > as org-id-method does not dictate the format of existing ids. Thanks for reporting! Tentative patch is attached. I have added some fallbacks for the default attach folder formatters, so that they can work when the ID does not conform to specific format. This change is somewhat opinionated, so feel free to suggest alternative solutions/fallback options. Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-attach-dir-from-id-Do-not-rely-on-ID-being-over-.patch >From e004752ba39f0d328645a1f6053ad3ce3b06ac28 Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Sat, 23 Jul 2022 13:13:24 +0800 Subject: [PATCH] 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 using ID md5 hash 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 "unknown/ID" path format when the ID contains less than 7 chars and cannot be split into the "YYYYMM/rest" path. Fixes https://orgmode.org/list/KC8PcypJapBpJQtJxM0kX5N7Z0THL2Lq6EQjBMzpw1-vgQf72egZ2JOIlTbPYiqAVD4MdSBhrhBZr2Ykf5DN1mocm1ANvvuKKZShlkgzKYM=@pm.me --- lisp/org-attach.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index 36c21b702..7c72fd7ee 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -159,19 +159,28 @@ (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), use its md5 hash to create +the path." + (if (< (length id) 3) + (org-attach-id-uuid-folder-format (md5 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 \"unknown/ID\"." + (if (< (length id) 7) + (format "unknown/%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) -- 2.35.1 --=-=-=--