From: Ihor Radchenko <yantar92@gmail.com>
To: Max Nikulin <manikulin@gmail.com>
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)]
Date: Wed, 10 Aug 2022 21:23:15 +0800 [thread overview]
Message-ID: <871qtodygs.fsf@localhost> (raw)
In-Reply-To: <td07l8$8gu$1@ciao.gmane.io>
[-- Attachment #1: Type: text/plain, Size: 2860 bytes --]
Max Nikulin <manikulin@gmail.com> 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v3-0001-org-attach-dir-from-id-Do-not-rely-on-ID-being-ov.patch --]
[-- Type: text/x-patch, Size: 2286 bytes --]
From 50d0f9de0acdf5d67b797476816cbeb40b19f554 Mon Sep 17 00:00:00 2001
Message-Id: <50d0f9de0acdf5d67b797476816cbeb40b19f554.1660137585.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
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
[-- Attachment #3: Type: text/plain, Size: 206 bytes --]
--
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
next prev parent reply other threads:[~2022-08-10 13:49 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 19:12 [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] Janek F
2022-07-23 5:22 ` [PATCH] " Ihor Radchenko
2022-08-02 22:26 ` Janek F
2022-08-03 16:03 ` Max Nikulin
2022-08-03 22:25 ` Ihor Radchenko
2022-08-10 11:43 ` [PATCH v2] " Ihor Radchenko
2022-08-10 12:17 ` Max Nikulin
2022-08-10 13:23 ` Ihor Radchenko [this message]
2022-08-10 15:18 ` [PATCH v3] " Max Nikulin
2022-08-11 4:19 ` Ihor Radchenko
2022-08-11 14:43 ` Max Nikulin
2022-08-13 5:29 ` Ihor Radchenko
2022-08-13 16:25 ` Max Nikulin
2022-08-14 4:00 ` Ihor Radchenko
2022-10-02 9:14 ` [PATCH v4] " Ihor Radchenko
2022-10-04 15:27 ` Max Nikulin
2022-10-05 5:44 ` Ihor Radchenko
2022-11-06 7:43 ` Ihor Radchenko
2022-11-07 17:05 ` [PATCH] org-attach.el: ID to path functions may return nil Max Nikulin
2022-11-08 5:08 ` Ihor Radchenko
2022-11-09 16:53 ` [PATCH v2] " Max Nikulin
2022-11-10 7:19 ` Ihor Radchenko
2022-11-13 16:26 ` Max Nikulin
2022-11-14 3:29 ` Ihor Radchenko
2022-11-14 16:59 ` Max Nikulin
2022-11-15 2:41 ` Ihor Radchenko
2022-11-15 16:41 ` Max Nikulin
2022-11-16 1:54 ` Ihor Radchenko
2022-08-12 15:35 ` [BUG] org-attach-id-ts-folder-format fails on customized IDs [9.6 (9.6-??-2e9999783)] Max Nikulin
2022-08-12 16:08 ` Janek F
2022-08-13 5:17 ` Ihor Radchenko
2022-08-13 15:59 ` Max Nikulin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871qtodygs.fsf@localhost \
--to=yantar92@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=manikulin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).