summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/file.c36
-rw-r--r--src/rep.c2
2 files changed, 34 insertions, 4 deletions
diff --git a/src/file.c b/src/file.c
index 4f42a5d..27db720 100644
--- a/src/file.c
+++ b/src/file.c
@@ -27,6 +27,12 @@
#if HAVE_UNISTD_H && HAVE_DIRENT_H
+int is_dots(struct dirent* entry)
+{
+ return entry->d_name &&
+ (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."));
+}
+
int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)
{
struct dirent* ent = 0;
@@ -52,9 +58,10 @@ int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)
}
}
#ifdef HAVE_FNMATCH
- while(0);
+ while(is_dots(ent));
#else
- while(fnmatch(wildcard, ent->d_name, FNM_PATHNAME) == FNM_NOMATCH);
+ while(is_dots(ent) ||
+ fnmatch(wildcard, ent->d_name, FNM_PATHNAME) == FNM_NOMATCH);
#endif
if(ent)
@@ -90,6 +97,12 @@ void dir_close(DIR* handle)
#include <direct.h>
#include <io.h>
+int is_dots(struct _finddata_t* findinfo)
+{
+ return findinfo->name &&
+ (!strcmp(findinfo->name, ".") || !strcmp(findinfo->name, ".."));
+}
+
static void copyDirStruct(struct _finddata_t* findinfo, struct dirent* entry)
{
/* Copy the structure */
@@ -139,6 +152,18 @@ DIR* dir_first(const char* folder, const char* wildcard, struct dirent* entry)
free(handle);
return INVALID_DIR;
}
+
+ /* We don't do dots */
+ else if(is_dots(&findinfo))
+ {
+ if(dir_next(handle, wildcard, entry))
+ return handle;
+
+ errno = ENOENT;
+ return INVALID_DIR;
+ }
+
+ /* Copy the first file */
else
{
copyDirStruct(&findinfo, entry);
@@ -151,7 +176,12 @@ int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)
struct _finddata_t findinfo;
int ret = _findnext(*handle, &findinfo) == 0;
if(ret)
- copyDirStruct(&findinfo, entry);
+ {
+ if(is_dots(&findinfo))
+ return dir_next(handle, wildcard, entry);
+ else
+ copyDirStruct(&findinfo, entry);
+ }
return ret;
}
diff --git a/src/rep.c b/src/rep.c
index b333ef5..6ff03c3 100644
--- a/src/rep.c
+++ b/src/rep.c
@@ -353,7 +353,7 @@ int replaceFolder(r_context* ctx, char* folder)
/* And for every file */
do
{
- if(ent.d_type & DT_DIR)
+ if(!(ent.d_type & DT_DIR))
{
int r = 0;