From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IL3FJQqa82JvNQAAbAwnHQ (envelope-from ) for ; Wed, 10 Aug 2022 13:44:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id OPTWJAqa82LVvgAAG6o9tA (envelope-from ) for ; Wed, 10 Aug 2022 13:44:10 +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 210301539D for ; Wed, 10 Aug 2022 13:44:10 +0200 (CEST) Received: from localhost ([::1]:41684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLk88-0007AA-Rq for larch@yhetil.org; Wed, 10 Aug 2022 07:44:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLk6l-00077h-QG for emacs-orgmode@gnu.org; Wed, 10 Aug 2022 07:42:43 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:38757) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oLk6j-00015y-Cw for emacs-orgmode@gnu.org; Wed, 10 Aug 2022 07:42:42 -0400 Received: by mail-pl1-x62f.google.com with SMTP id o3so14006654ple.5 for ; Wed, 10 Aug 2022 04:42:39 -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; bh=WEif7A078mbUMiTl8pHOtQg11pmSLuM+M8VKnZ35Yb4=; b=MAoGUC6UbBc+zh3aaOLrQO2WAhOpkllYZ+ch2mpgGYxub5y3TPBYeO/WhlhVF/HtkK jCuE7APY5fR1PXIvF6LQlxo9cGUxYrmzIrXWAqK3BvPdtAmhbgNF1e13x+RNXZD4JMYo cFOsdx3RC/H0T0Q4jOJi8ejYDfp3yAwxrlJneoJuPJ7b0dzdMMyD5j+SQlHWMTUQBY15 cRZAnfxVMK32P2tqUf499oCrrfkKf4aeKV66OOERFfROcrsoNsGcxMmIvBbQUCI3fejF TVF9OC/e2gY36WMu6uau0Bdozom4NX+DqN2yl2QD2sUaYOFjrUTNpCwRQuf+hgv651Ne gI+A== 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; bh=WEif7A078mbUMiTl8pHOtQg11pmSLuM+M8VKnZ35Yb4=; b=tmLL3MnHDhBNFQ6TgRHgbnSTnma6pG2MGFSR6b+meyXbPOzk2YebzbVDPX6HPBfV8I qZz2pVftM9gm4CdQPrg4QMZkCX65LfOiT7o8xL0/1X9BqqyHLUCm4w7fAyHDr3QMrACv LsznKattDsxjSGm97WIGokBfq+fuKQWneHCi2yAtMDJWTWdI1pFvUXlHdLZP2vShF5dp rZHy6E0vTtsnjDsWQfbvbP2bjkkoAb+I40U6KXk2nnhhlYBJ4gh0rh+xoeBNIVAy+FLC JeeMOL80SLDmGp8z5ovw8skqiJn8FwkqliPo8bWs12oR1lMWEB+lmmOKMMLQeMS8x137 6FZA== X-Gm-Message-State: ACgBeo2wQ7eCKrW0c71V7KWoRfwdVqksFrfO5I+0DNtvl1+2+tuSTP2k 5xcp7F+3V7QYiABZaQaNHvI= X-Google-Smtp-Source: AA6agR7DPiM8j5N03v5XC/epJMXpAiF8RcpQYLHNJJUHZ1vI4Ms2sLlqM7LywWgPXStgDD2UWbn5Wg== X-Received: by 2002:a17:90b:1c0c:b0:1f5:494a:304b with SMTP id oc12-20020a17090b1c0c00b001f5494a304bmr3346545pjb.157.1660131758255; Wed, 10 Aug 2022 04:42:38 -0700 (PDT) Received: from localhost ([2409:8a70:2bf:80b0:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id y17-20020a170902cad100b0016d9d6d05f7sm12411669pld.273.2022.08.10.04.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 04:42:37 -0700 (PDT) From: Ihor Radchenko To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: [PATCH v2] Re: [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] In-Reply-To: <871qtxhsm6.fsf@localhost> References: <87k084v1wa.fsf@localhost> <871qtxhsm6.fsf@localhost> Date: Wed, 10 Aug 2022 19:43:37 +0800 Message-ID: <87a68ce32u.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=yantar92@gmail.com; helo=mail-pl1-x62f.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=1660131850; 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=WEif7A078mbUMiTl8pHOtQg11pmSLuM+M8VKnZ35Yb4=; b=jAbTdteMyfgh3F1ZycAUitYIeWo4tms0t9UPTLSXMXiWCmXEO6qzxNL/WkgiH7dD77M0Mf AMcvwLCfr40243Tnyn3H8nejflYySYAvmfMpJ8ANROt36cmBysDYzW/ZB97+M/YUppEJyV KAV1m0/CgpVdrD1LHxC7Llg0j2TED3bTt3IgvhP8XgZ4eXdRAAgE2EiaHL1r7eZFR6k6lk XIgsBR3N88rad2/joQ4Uoi5EOpzzA5oxqzeim4DXS3WE6rAxm3Sf//E1RZEqCgAqRJ75un WwQoIBBhMDAZw+GER7UWaIZWnkqi1L7I4MqxPnYensNF5yxzSXUjxb2SipLBUA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1660131850; a=rsa-sha256; cv=none; b=kdRflqSq7RGc3ZwkZjs44vXaYVmwXxSGaDXYmeyBSccaU179B5inuR32sAY5fpJYtlcVld EMtPm0pzZ7ST8+J2z3b9rcL9Mdsg+yReRPV2EiQEbDf8Z9n0sQyvShfOCjXb37+PFB1dVy HvPg7bUrGXWNORWR/iBgihEsRoccGk+E98LCpIwjXf6TXQsoYUT1jf5AT0KtYfz4qqx4Gm wKEJmct3Wl0gmaZwdW4ykco9fVXx4gwVG+Ctq5c/uhLtUBiFC9+XSWZwBjas719bMClf0c /NWaShqX0jph6g0vRqDUCFxCTnAuk+erS2cWArlZYu1PtTyzqF/JTUqvhA+9Ew== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MAoGUC6U; 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.39 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MAoGUC6U; 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: 210301539D X-Spam-Score: -3.39 X-Migadu-Scanner: scn1.migadu.com X-TUID: r3nfU4XQgRBQ --=-=-= Content-Type: text/plain Ihor Radchenko writes: >> Ihor, I am afraid of collisions due to short input to md5. Long hash >> value gives false impression of high entropy but actually there are not >> so many variants for 1 or 2 characters strings. Either there is no point >> in making long name from short id or random string of appropriate length >> should be used instead. > > Random is not an option. If we use random string, how will we get the > right attachment path on a second call? This function must return the > same value given the same input. > > Having said that, I do agree (taking into account the other comment) > that md5 may not be a very good idea. Maybe simply something like > "__/id". Ideally, we should be able to recover the original id from the > path to attachment. I have updated the patch to use "__/id" when id is too short. Any objections? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0001-org-attach-dir-from-id-Do-not-rely-on-ID-being-ov.patch >From 7ca5fe66c53a1399943a2e2d4a1675ca8cd14194 Mon Sep 17 00:00:00 2001 Message-Id: <7ca5fe66c53a1399943a2e2d4a1675ca8cd14194.1660131747.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sat, 23 Jul 2022 13:13:24 +0800 Subject: [PATCH v2] 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 "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 fe49af6f3..bb7c787f7 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) + (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 \"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 --=-=-= 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 --=-=-=--