[nautilus/max-name-length: 12/12] directory: Add method to query maximum filename length



commit 07073efe2e7436340b0ab88aaaafbd968859f487
Author: Ernestas Kulik <ernestask gnome org>
Date:   Thu Feb 15 15:19:59 2018 +0200

    directory: Add method to query maximum filename length
    
    This is to be used by a potential fix for
    https://gitlab.gnome.org/GNOME/nautilus/issues/148.

 src/nautilus-directory.c | 30 ++++++++++++++++++++++++++++++
 src/nautilus-directory.h | 13 +++++++++++++
 2 files changed, 43 insertions(+)
---
diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c
index 0ab13dbbe..1b11d7709 100644
--- a/src/nautilus-directory.c
+++ b/src/nautilus-directory.c
@@ -692,6 +692,36 @@ nautilus_directory_new_file_from_filename (NautilusDirectory *directory,
                                                                                               self_owned);
 }
 
+glong
+nautilus_directory_get_max_child_name_length (NautilusDirectory *self)
+{
+    g_autoptr (GFile) location = NULL;
+    g_autofree gchar *path = NULL;
+    glong path_length;
+    glong name_max;
+    glong path_max;
+    glong result;
+
+    g_assert (NAUTILUS_IS_DIRECTORY (self));
+
+    location = nautilus_directory_get_location (self);
+    path = g_file_get_path (location);
+    path_length = strlen (path);
+
+    g_assert (path != NULL);
+
+    name_max = pathconf (path, _PC_NAME_MAX);
+    if (name_max == -1)
+    {
+        return -1;
+    }
+    path_max = pathconf (path, _PC_PATH_MAX);
+    /* Subtracting one from NAME_MAX, since the length excludes the null terminator. */
+    result = MAX (MIN (path_max - path_length, name_max - 1), 0);
+
+    return result;
+}
+
 static GList *
 nautilus_directory_provider_get_all (void)
 {
diff --git a/src/nautilus-directory.h b/src/nautilus-directory.h
index 66daa34f7..9f41945d0 100644
--- a/src/nautilus-directory.h
+++ b/src/nautilus-directory.h
@@ -250,3 +250,16 @@ void               nautilus_directory_dump                     (NautilusDirector
 NautilusFile *     nautilus_directory_new_file_from_filename   (NautilusDirectory *directory,
                                                                 const char        *filename,
                                                                 gboolean           self_owned);
+
+/**
+ * nautilus_directory_get_max_child_name_length:
+ * @directory: a #NautilusDirectory
+ *
+ * Gets the maximum file name length for files inside @directory.
+ *
+ * This call does blocking I/O.
+ *
+ * Returns: The maximum file name length in bytes, -1 if the maximum length
+ *          could not be determined or 0 if @directory path is too long.
+ */
+glong nautilus_directory_get_max_child_name_length (NautilusDirectory *directory);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]