diff options
author | Stef Walter <stef@thewalter.net> | 2004-04-07 18:47:00 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2004-04-07 18:47:00 +0000 |
commit | bf2dfe574ae38c5acea28648c379effad44aa970 (patch) | |
tree | 555ccc6056e457bd44693f284d02d06541cde822 | |
parent | 08c1eaa8aa0e6928bb5067df417ac785c1bce326 (diff) |
Folder emuration fixes.
-rw-r--r-- | src/file.c | 36 | ||||
-rw-r--r-- | src/rep.c | 2 |
2 files changed, 34 insertions, 4 deletions
@@ -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; } @@ -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; |