[beast/win32] Fixed a few directory / path separator issues in the file crawler code.
- From: Stefan Westerfeld <stw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [beast/win32] Fixed a few directory / path separator issues in the file crawler code.
- Date: Sat, 5 Sep 2009 09:50:16 +0000 (UTC)
commit 063fcb654f371b9c92851b55286db928dbb6c4a9
Author: Stefan Westerfeld <stefan space twc de>
Date: Sat Sep 5 09:48:59 2009 +0200
Fixed a few directory / path separator issues in the file crawler code.
Based on 010_plugin_ext_crawler.diff.
sfi/sfifilecrawler.c | 49 +++++++++++++++++++++++++++++++++----------------
1 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/sfi/sfifilecrawler.c b/sfi/sfifilecrawler.c
index edfbfd3..8b55033 100644
--- a/sfi/sfifilecrawler.c
+++ b/sfi/sfifilecrawler.c
@@ -19,8 +19,7 @@
#include "sfiwrapper.h"
#include "topconfig.h"
#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <sys/stat.h>
#define INCREMENTAL_RESULTS 1
@@ -173,7 +172,7 @@ file_crawler_queue_readdir (SfiFileCrawler *self,
if (strchr (file_pattern, '?') || strchr (file_pattern, '*'))
{
gchar *s = g_strconcat (base_dir, G_DIR_SEPARATOR_S, NULL);
- self->dhandle = opendir (s);
+ self->dhandle = g_dir_open (s, 0, NULL);
g_free (s);
if (self->dhandle)
{
@@ -199,16 +198,17 @@ file_crawler_queue_readdir (SfiFileCrawler *self,
static void /* self->accu is implicit in/out arg */
file_crawler_crawl_readdir (SfiFileCrawler *self)
{
- DIR *dd = self->dhandle;
- struct dirent *d_entry = readdir (dd);
+ /* FIXME:stw: either this function is by design only supposed to be called
+ * with self->dhandle != NULL, or my win32 changes need fixing
+ */
+ g_return_if_fail (self->dhandle != NULL);
- if (d_entry)
+ const gchar *filename = g_dir_read_name (self->dhandle);
+ if (filename)
{
- if (!(d_entry->d_name[0] == '.' && d_entry->d_name[1] == 0) &&
- !(d_entry->d_name[0] == '.' && d_entry->d_name[1] == '.' && d_entry->d_name[2] == 0) &&
- g_pattern_match_string (self->pspec, d_entry->d_name))
+ if (g_pattern_match_string (self->pspec, filename))
{
- gchar *str = g_strconcat (self->base_dir, G_DIR_SEPARATOR_S, d_entry->d_name, NULL);
+ gchar *str = g_strconcat (self->base_dir, G_DIR_SEPARATOR_S, filename, NULL);
if (self->ftest && !g_file_test_all (str, self->ftest))
g_free (str);
else
@@ -221,12 +221,29 @@ file_crawler_crawl_readdir (SfiFileCrawler *self)
self->pspec = NULL;
g_free (self->base_dir);
self->base_dir = NULL;
- closedir (dd);
+ g_dir_close (self->dhandle);
self->dhandle = NULL;
self->ftest = 0;
}
}
+/* On unix, it is equivalent with strchr (path, '/').
+ *
+ * On windows, it takes into account that both, '/' and '\' are
+ * valid directory separators.
+ */
+static gchar*
+find_next_dir_separator (const gchar *path)
+{
+ while (*path && !G_IS_DIR_SEPARATOR (*path))
+ path++;
+
+ if (*path)
+ return path;
+ else
+ return NULL;
+}
+
static void
file_crawler_queue_abs_file_path (SfiFileCrawler *self,
const gchar *path_pattern,
@@ -239,7 +256,7 @@ file_crawler_queue_abs_file_path (SfiFileCrawler *self,
freeme = p = g_strdup (path_pattern);
/* seperate root */
- sep = strchr (p, G_DIR_SEPARATOR);
+ sep = find_next_dir_separator (p);
g_return_if_fail (sep != NULL); /* absolute paths must have a seperator */
*sep++ = 0;
@@ -257,12 +274,12 @@ file_crawler_queue_abs_file_path (SfiFileCrawler *self,
self->dlist = sfi_ring_prepend (self->dlist, g_strdup (p));
/* compress multiple dir seperators */
- while (*sep == G_DIR_SEPARATOR)
+ while (G_IS_DIR_SEPARATOR (*sep))
sep++;
/* add remaining segments to queue */
p = sep;
- sep = strchr (p, G_DIR_SEPARATOR);
+ sep = find_next_dir_separator (p);
while (sep)
{
*sep++ = 0;
@@ -271,7 +288,7 @@ file_crawler_queue_abs_file_path (SfiFileCrawler *self,
while (*sep == G_DIR_SEPARATOR)
sep++;
p = sep;
- sep = strchr (p, G_DIR_SEPARATOR);
+ sep = find_next_dir_separator (p);
}
/* final segment */
@@ -344,7 +361,7 @@ path_make_absolute (const gchar *rpath,
gchar *home, *user = NULL;
if (rpath[0] != '~')
return cwd ? g_strconcat (cwd, G_DIR_SEPARATOR_S, rpath, NULL) : NULL;
- dir = strchr (rpath + 1, G_DIR_SEPARATOR);
+ dir = find_next_dir_separator (rpath + 1);
if (dir && dir > rpath + 1)
user = g_strndup (rpath + 1, dir - rpath - 1);
else if (!dir && rpath[1])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]