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 UKa/HGa382LJBAAAbAwnHQ (envelope-from ) for ; Wed, 10 Aug 2022 15:49:26 +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 OM3UG2a382KF1gAAG6o9tA (envelope-from ) for ; Wed, 10 Aug 2022 15:49:26 +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 D9C642A165 for ; Wed, 10 Aug 2022 15:49:24 +0200 (CEST) Received: from localhost ([::1]:53948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLm5L-0000SF-Fv for larch@yhetil.org; Wed, 10 Aug 2022 09:49:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLlfG-0001GR-GB for emacs-orgmode@gnu.org; Wed, 10 Aug 2022 09:22:30 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:33545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oLlfE-00055W-85 for emacs-orgmode@gnu.org; Wed, 10 Aug 2022 09:22:26 -0400 Received: by mail-pg1-x52a.google.com with SMTP id l64so14389397pge.0 for ; Wed, 10 Aug 2022 06:22:23 -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=7W7YY7V2UxhoJu9F97CqPvt7uGasULq9dNgm680jyUM=; b=Wq6wj0Rcy/6LibxE95Ut1ouKfMAS2rC4ivYHiKPIzDCSBCxKD6Fy7olOPxOL1XIHTL xputns2KPZxClX58uS1ZSKwsYP6BRhny2L570PJN5NSs/6hz2bqkAR54dIFC1l/JEVij EKQc3vnSJZzIC3AI1ZPqPOuEloSR0uTDtO1tq7iau7N3gHWCrdie8M493k0Qn39b+S5p BHeEB0Nh70J8b/Hoxx1EIhhwvBa08Sjsc5Mh2VoDVGkRRNbm+Z67x119c7ZeeJ+C5UTu jz7OcKnbUFwxbG/dQ0zNPEcOJT67OBXzLyBvi9kq83AEEKdWN5jYzoPY4KxXeYcC3dzf H8Kg== 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=7W7YY7V2UxhoJu9F97CqPvt7uGasULq9dNgm680jyUM=; b=TG7yTW+uCxVDzlUAK3wDMO+LWmLv8Gt/2XX44TwTzGWKnGf9AkRY+/S12WeSoXrzOv NkTg4csQaVCg5cbpDX1CWBn+EMD6j917NPyFoByRGn8HT7/mrofW6TkgppNC3eZIHWN2 ztuIyq1S3iFW8a4nNNTmIfeNJMdupwoclVhp8jy7ylCiOjiuqJJzXZguPZmdfooucGY8 l6iKoamlD/uh7QeroJamhZvAcIRM1pWcHGT9p5iN6Ioz81T/sTizMFz+eyqaw9Hcf332 Wab2av0cq4aPDJJ6o9Q2yzouvvYyPFxo6Z6h05abE+24MWuVl3xWQxhkQv7GPgyv39m7 +4uQ== X-Gm-Message-State: ACgBeo1xWHKOYtAGxNAwhNNSj31fiFcZ00yNBEShbUSD0WXyzTNS27wR DfE+XU78JPrm3ByIJXV2aLVbg7R400HSFw== X-Google-Smtp-Source: AA6agR5Gab46TOrKfzstLddda4UHnG7hZAdBD9WOueRpaA0T8Td5K0FFRB1yw6Om+yV4neMmkXH2yA== X-Received: by 2002:a63:8ac9:0:b0:41b:bd60:672b with SMTP id y192-20020a638ac9000000b0041bbd60672bmr23262281pgd.70.1660137742239; Wed, 10 Aug 2022 06:22:22 -0700 (PDT) Received: from localhost ([2409:8a70:2bf:80b0:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id p3-20020a170902780300b0016d10267927sm12710602pll.203.2022.08.10.06.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 06:22:21 -0700 (PDT) From: Ihor Radchenko To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: [PATCH v3] Re: [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] In-Reply-To: References: <87k084v1wa.fsf@localhost> <871qtxhsm6.fsf@localhost> <87a68ce32u.fsf@localhost> Date: Wed, 10 Aug 2022 21:23:15 +0800 Message-ID: <871qtodygs.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=yantar92@gmail.com; helo=mail-pg1-x52a.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=1660139365; 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=7W7YY7V2UxhoJu9F97CqPvt7uGasULq9dNgm680jyUM=; b=uJSteTky2eQi5ockwPMeop1ixe8zLg05op64vbMD7LyCGaNdbVyUIipo53n7fPfsqu7jVj dUYjH/7ceentxiJgXP4TLEWaUlc5bA6uhgN1668CdaVbXwrNaoxvI8rOwgtH6ANC+6bxsv Rf1r6HHzkPq3AG1sg5uys92Fv1RPqxe1ZVrtrXXCRvTzOf9HFH3vI+JrwGMEtAwyNqGZma mPR1LY3d18AKXP7iW+2RFt3N7yErFj85i68th8Uv1SHOJ2OUa+iwyG264b1cGzR7PPMZ8S werMznvaqs8zzF7zpgAzJoq8zbaMz9vdMsM7KNvkqEBUcpiVOv/UfFkinpZNmw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1660139365; a=rsa-sha256; cv=none; b=Ghz0hkmDX63Cptr0lAFRjs5Tc0pVMNMDeMFR2IkKKeyQdprBoH+bmIo2fmFZ3ZZDbcuJtm U+VmXXdn/s+tFQPnoOltxD+79AuWu7YfvLMMbMx+Pg5prHRzsNLZqVv2BoqUVEZ4bKUq8L QAM98qDjZ+nYze4bFZzpaekz1av6VTCSKz3UWVLFiyOrYk3T6CWXq52gHiO4aWsSkM1pek 5lri3uUNzE6fdvXnmWikMlcmhZ7kBmMWFTIm9gQyYsBoY5xlqFPu+5DglNzzaO71uK5pDV BH5EAHRIsoTZCRwypl+zmfUqQkaUw+h9G6LMaYIlMSXWXkrYJ+o087rlf+Tl9Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Wq6wj0Rc; 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: -6.89 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Wq6wj0Rc; 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: D9C642A165 X-Spam-Score: -6.89 X-Migadu-Scanner: scn0.migadu.com X-TUID: npYfgRBxp+kp --=-=-= Content-Type: text/plain Max Nikulin writes: > On 10/08/2022 18:43, Ihor Radchenko wrote: >> Ihor Radchenko writes: >> >> I have updated the patch to use "__/id" when id is too short. >> Any objections? >> >> +When ID is too short (less than 3 chars), use its md5 hash to create > > Misleading docs, you do not use md5. Oops. Will fix. >> +the path." >> + (if (< (length id) 3) >> + (format "--/%s" id) > > Please, do not use path components starting with dash, it is terrible > for CLI tools. By the way, you promised underscores, not dashes. Why? I have no opinion about the possible dummy folder name, except that it should fit the general pattern we already have "xx/..." or "YYYYMM/...". >> + (format "%s/%s" >> + (substring id 0 2) >> + (substring id 2)))) > > Ihor, I have not look into the code around, so my suggestions may have > no sense. > > Is it possible to pass empty string as ID to these functions? Should it > be explicitly checked? It should not be possible under normal operation. > What if ID contains "/" that can not be used in file name? Windows has > more forbidden characters. Then, creating the attachment dir will fail in front of the user. I am not sure if we really need to do much about this. At least, not until we get a bug report. If we really need to solve the edge cases with attach dir generation, we may need to change the overall design in org-attach/org-id to something more restrictive. I am not sure if it is worth the effort compared to other directions where to improve Org. > Do you expect any problem if here (and for timestamp-based ids) > directory component is just padded with some character (unsure what can > better than underscore) to required length? > > "x" -> "_x/x" or "______x/x" > "xy" -> "xy/xy" or "_____xy/xy" > etc. > > From my point of view it might be a bit better than "__" and "unknown". Does it make sense? Timestamp-based IDs are like 20220810T210121.478800 by default. Then, the top-level folders will be like 202208/... If the actual format is different, we cannot possibly expect the timestamp to follow the same pattern, which is why I chose "unknown" referring to unknown date. On the other hand, if an ID has more than 6 characters, it will generate nonsense top-level folder with or without the patch. We could go further and match the ID against [1-9][0-9]\{5\} and put the folder into "unknown/ID" instead, but that would be a breaking change. In summary, I am more of less neutral towards this fallback format, except that it would be nice to be able to recover the ID from the directory path. Padding should be recoverable. I slightly dislike the "___xx" compared to "______" because it will create a proliferation of top-level folders as opposed to cramping the non-standard IDs into a single "______" folder. Attaching the updated patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v3-0001-org-attach-dir-from-id-Do-not-rely-on-ID-being-ov.patch >From 50d0f9de0acdf5d67b797476816cbeb40b19f554 Mon Sep 17 00:00:00 2001 Message-Id: <50d0f9de0acdf5d67b797476816cbeb40b19f554.1660137585.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sat, 23 Jul 2022 13:13:24 +0800 Subject: [PATCH v3] 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. Fixes https://orgmode.org/list/KC8PcypJapBpJQtJxM0kX5N7Z0THL2Lq6EQjBMzpw1-vgQf72egZ2JOIlTbPYiqAVD4MdSBhrhBZr2Ykf5DN1mocm1ANvvuKKZShlkgzKYM=@pm.me --- lisp/org-attach.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index fe49af6f3..0f5d5af82 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -159,19 +159,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) -- 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 --=-=-=--