[nautilus/max-name-length] directory: add method to query maximum filename length
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/max-name-length] directory: add method to query maximum filename length
- Date: Thu, 15 Feb 2018 13:46:31 +0000 (UTC)
commit 0587e15f0a8ab928fbf9f1bee1f334173f7afb72
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 | 43 +++++++++++++++++++++++++++++++++++++++++++
src/nautilus-directory.h | 14 ++++++++++++++
2 files changed, 57 insertions(+)
---
diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c
index 0f6412e34..edf3ff43c 100644
--- a/src/nautilus-directory.c
+++ b/src/nautilus-directory.c
@@ -40,6 +40,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <errno.h>
+
enum
{
FILES_ADDED,
@@ -692,6 +694,47 @@ nautilus_directory_new_file_from_filename (NautilusDirectory *directory,
self_owned);
}
+glong
+nautilus_directory_get_max_child_name_length (NautilusDirectory *self,
+ GError **error)
+{
+ g_autoptr (GFile) location = NULL;
+ g_autofree char *path = NULL;
+ glong result;
+
+ g_assert (NAUTILUS_IS_DIRECTORY (self));
+
+ location = nautilus_directory_get_location (self);
+ path = g_file_get_path (location);
+
+ g_assert (path != NULL);
+
+ /* pathconf() can return -1 if the maximum length is indefinite,
+ * in that case, errno is not set, so the only way to know is to
+ * check if errno is 0.
+ */
+ errno = 0;
+
+ result = pathconf (path, _PC_NAME_MAX);
+ if (result == -1)
+ {
+ int errsv;
+
+ errsv = errno;
+
+ if (errsv == 0)
+ {
+ return FILENAME_MAX;
+ }
+
+ g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
+ "Could not get maximum name length for children in %s: %s",
+ path, g_strerror (errsv));
+ }
+
+ return result;
+}
+
static GList *
nautilus_directory_provider_get_all (void)
{
diff --git a/src/nautilus-directory.h b/src/nautilus-directory.h
index a16b9c43d..076be0ac6 100644
--- a/src/nautilus-directory.h
+++ b/src/nautilus-directory.h
@@ -252,4 +252,18 @@ NautilusFile * nautilus_directory_new_file_from_filename (NautilusDirector
const char *filename,
gboolean self_owned);
+/**
+ * nautilus_directory_get_max_child_name_length:
+ * @directory: a #NautilusDirectory
+ * @error: (nullable): a #GError or %NULL
+ *
+ * Gets the maximum file name length for files inside @directory.
+ *
+ * This call does blocking I/O.
+ *
+ * Returns: The maximum file name length in bytes or -1 if an error occured.
+ */
+glong nautilus_directory_get_max_child_name_length (NautilusDirectory *directory,
+ GError **error);
+
#endif /* NAUTILUS_DIRECTORY_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]