After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 742050 - Filename length should be taken into account
Filename length should be taken into account
Status: RESOLVED OBSOLETE
Product: easytag
Classification: Other
Component: general
2.3.x
Other All
: Normal enhancement
: 2.2
Assigned To: EasyTAG maintainer(s)
EasyTAG maintainer(s)
: 767314 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-12-28 05:25 UTC by J.B. Nicholson
Modified: 2021-05-26 09:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to resolve filename exceeding maximum allowed filename length (6.87 KB, patch)
2016-03-01 20:40 UTC, Pranav Ganorkar
needs-work Details | Review

Description J.B. Nicholson 2014-12-28 05:25:00 UTC
Filesystems typically impose a limit on filename length (for example, ext3/ext4 have a max filename length of 255 bytes according to Wikipedia). It would be good if EasyTAG took this limit into account when renaming files.

I'm not sure how to properly detect the appropriate length, but I suggest 255 characters (or whatever unit is appropriate) as a default filename limit in case this isn't detectable at runtime. I also suggest keeping the dot extension of the filename in case the user is using a file browser that depends on them for proper file identification.

Unfortunately I'm not sure how to handle cases where the filename gets to be too long. Perhaps simply truncating the desired filename enough to allow the dot extension and simultaneously not exceed the length limit will be sufficient.
Comment 1 David King 2014-12-28 09:45:09 UTC
255 bytes is probably a sufficiently-common limit to use for all filesystems.
Comment 2 Pranav Ganorkar 2016-03-01 20:40:34 UTC
Created attachment 322800 [details] [review]
Patch to resolve filename exceeding maximum allowed filename length

Added handling of multiple as well single file renaming cases.
Comment 3 Pranav Ganorkar 2016-03-01 20:42:01 UTC
Hi, I have created a patch. Please Review it.
Comment 4 David King 2016-03-02 08:36:14 UTC
Review of attachment 322800 [details] [review]:

::: src/easytag.c
@@ +669,3 @@
                     }
 
+                    // if file name exceeds max length on file system and there are multiple files

This comment is superfluous with the if check on the following line.

@@ +670,3 @@
 
+                    // if file name exceeds max length on file system and there are multiple files
+                    else if(error->code == G_FILE_ERROR_NAMETOOLONG && multiple_files)

Add a space before the opening bracket (check the HACKING file for some more coding style details). Use g_error_matches(): https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#g-error-matches

@@ +673,3 @@
+                    {
+
+                        // Check length of filename (limit ~255 characters) and truncate accordingly

Use C89 comments. I just added a mention of this to the HACKING file.

@@ +677,3 @@
+                    }
+
+                    // if file name exceeds max length on file system and is just a single file

Superfluous comment.

@@ +680,3 @@
+                    else if(error->code == G_FILE_ERROR_NAMETOOLONG && !multiple_files)
+                    {
+                        msgdialog = gtk_message_dialog_new (GTK_WINDOW (MainWindow),

How can the user resolve the dialogue? It informs the user that the filename is too long but does not give the user an opportunity to resolve the problem. Additionally, the user is not given the name of the problematic file.

@@ +684,3 @@
+                                                            GTK_MESSAGE_ERROR,
+                                                            GTK_BUTTONS_CLOSE,
+                                                            _("File name too long. Please enter a file name with less characters."));

"fewer" not "less", as a filename is a discrete quantity. Also, use "filename" and not "file name".

@@ +699,1 @@
                     Log_Print (LOG_ERROR,

This code needs re-indenting.

::: src/file.c
@@ +1844,3 @@
 }
+
+/* Check if the basename+extension of the file doesn't exceed following limits :

Do not simply resurrect the old code for checking the length of the file, but improve it while doing so. This comment should use a gtk-doc style, similar to (for example) et_filename_prepare().

@@ +1851,3 @@
+ *    - 'filename_utf8' filename without the extension
+ */
+void ET_File_Name_Check_Length (ET_File *ETFile, gchar *filename_utf8)

Place the "void" on a line by itself, and keep the parameters on separate lines.

@@ +1853,3 @@
+void ET_File_Name_Check_Length (ET_File *ETFile, gchar *filename_utf8)
+{
+    ET_File_Description *ETFileDescription;

There's not much need to have this as a variable, as it is never modified and used only once.

@@ +1855,3 @@
+    ET_File_Description *ETFileDescription;
+    gchar *basename;
+    gint  exceed_size;

strlen() returns size_t (or gsize), not gint.

@@ +1858,3 @@
+
+
+    if (!ETFile || !filename_utf8) return;

These invariant checks should use g_return_if_fail().

@@ +1865,3 @@
+    switch (ETFileDescription->FileType)
+    {
+#ifdef ENABLE_OGG

Check whether Ogg files are the only ones where a temporary rename is used, and check that an extra 6 characters (as used below) are sufficient.

@@ +1869,3 @@
+            if ( (exceed_size = (strlen(basename) - 245)) > 0 ) // 255 - 4 (extension) - 6 (mkstemp)
+            {
+                Log_Print(LOG_ERROR,_("The filename '%s' exceeds %d characters and will be truncated"), filename_utf8, 245);

It does not really make sense to log messages in this code, and instead the caller should log messages (or handle the error appropriately). This implies that a GError should be set if truncation occurs. Look at et_rename_file() for an example.

@@ +1875,3 @@
+#endif
+        default:
+            if ( (exceed_size = (strlen(basename) - 251)) > 0 ) // 255 - 4 (extension)

Are all filename extensions 4 characters (3 characters for the extension plus a full stop)?
Comment 5 David King 2016-06-07 06:43:35 UTC
*** Bug 767314 has been marked as a duplicate of this bug. ***
Comment 6 André Klapper 2021-05-26 09:51:36 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new enhancement request ticket at
  https://gitlab.gnome.org/GNOME/easytag/-/issues/

Thank you for your understanding and your help.