Skip to content

Commit

Permalink
fixed recursive searches using UNC paths on Windows; + optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Dec 19, 2015
1 parent 9ae8487 commit 56f6ef4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog for 'id3'.

2015-352 (W51):
fileexp.cpp: '?' will no langer match against / in --recursive mode;
-R was not working on UNC paths. optimized file access.

2015-348 (W50):
main.cpp: %a variable substitution now will read from the first valid
tag selected on the commandline, instead of only the first
Expand Down
34 changes: 17 additions & 17 deletions fileexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/*
copyright (c) 2004, 2005 squell <squell@alumina.nl>
copyright (c) 2004, 2005, 2015 squell <squell@alumina.nl>
use, modification, copying and distribution of this software is permitted
under the conditions described in the file 'COPYING'.
Expand All @@ -28,7 +28,6 @@ using namespace std;

namespace fileexp {


/* filefind::nested variables split in two categories: stuff that drives the
the recursion (parameters); and supporting information (class members) */

Expand All @@ -51,16 +50,17 @@ bool find::glob(const char* filemask, bool wildslash)
t.rec_base = wildslash? t.path : 0;
#if defined(_WIN32)
if(strncmp(t.mask, "//", 2) == 0) { // unc path
char* shmask = strchr(t.mask+2, '/');
if(shmask && (shmask=strchr(++shmask, '/'))) {
*shmask++ = '\0'; // separate sharename
char* shpath = t.pathcpy(t.pathcpy(t.path, t.mask), "/");
return t.nested(auto_dir(t.mask), shpath, shmask);
}
return false;
char* shmask = strchr(t.mask+2, '/');
if(shmask && (shmask=strchr(++shmask, '/'))) {
*shmask++ = '\0'; // separate sharename
char* shpath = t.pathcpy(t.pathcpy(t.path, t.mask), "/");
if(t.rec_base) t.rec_base = shpath;
return t.nested(auto_dir(t.mask), shpath, shmask);
}
return false;
} else
#endif
return t.nested(auto_dir("./"), t.path, t.mask);
return t.nested(auto_dir("./"), t.path, t.mask);
}

struct filefind::direxp : varexp { // special dotfile handling
Expand Down Expand Up @@ -113,7 +113,7 @@ bool filefind::nested(auto_dir dir, char* pathpos, char* filespec)

bool w = false; // idle check

if(!rec_base || path == pathpos)
if(!rec_base || rec_base == pathpos)
while( char* fndirsep = strchr(filespec, '/') ) {
slash_split lock(fndirsep++);
wpos = pathcpy(pathcpy(pathpos, filespec), "/");
Expand All @@ -122,15 +122,16 @@ bool filefind::nested(auto_dir dir, char* pathpos, char* filespec)
pathpos = wpos; // directory, use as is
filespec = fndirsep; // (tail recursion)
if(rec_base) rec_base = pathpos;
} else if(!strpbrk(filespec, "*?") || !dir) {
} else if(!strpbrk(filespec, "*?[") || !dir) {
return false; // shortcut mismatchers
} else if(rec_base) {
} else if(rec_base && strchr(filespec,'*')) {
break;
} else {
while( dirent* fn = dir.read() ) { // search cur open dir
direxp match(filespec, fn->d_name);
if(match) {
wpos = pathcpy(pathcpy(pathpos, fn->d_name), "/");
if(rec_base) rec_base = wpos;
if(auto_dir newdir = auto_dir(path)) {
for(varexp::iterator i = match.begin(); i != match.end(); ++i)
var.push_back(*i);
Expand All @@ -149,10 +150,9 @@ bool filefind::nested(auto_dir dir, char* pathpos, char* filespec)
if(*filespec == '\0')
return invoker->file(pathpos, *this);

if(!rec_base && access(filespec, F_OK) == 0) {
pathcpy(pathpos, filespec); // check if file is 'simple'
return invoker->file(pathpos, *this); // (speeds up simple cases)
}
pathcpy(pathpos, filespec); // check if file is 'simple'
if(!strpbrk(filespec, "*?["))
return access(path, F_OK) == 0 && invoker->file(pathpos, *this);

if(! dir ) // we might not have read access
return false;
Expand Down
5 changes: 2 additions & 3 deletions id3.man
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ will by default
attempt to read ID3v2, Lyrics3 and ID3v1 tags in that order, only modify existing ID3v2 and Lyrics3 tags, and modify/add ID3v1 tags.
.TP
.BR \-R ", " \-\-recursive
searches recursively; Normally, path separators in \fIfilespec\fR do not get
matched by `?' or `*' wildcards. With this switch, they are treated as an
ordinary character.
searches recursively; When this is enabled, `*' wildcards in \fIfilespec\fR will also match against
directory separators. Normally, this is not the case.
.TP
.BR \-M ", " \-\-keep\-time
preserve last modification time of files operated on
Expand Down
2 changes: 1 addition & 1 deletion test/globbing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while [ $iter -lt 50 ]; do
# id3 will never match "." ".." against wildcards intended to match files;
# so we need to filter those; also, filter anything containing /proc/ or /dev/

find $files -prune 2> /dev/null | grep -v '[.]\{1,2\}$' | grep -v -e "/proc/" -e "/dev/" | sort > /tmp/test1
find $files -prune 2> /dev/null | grep -v '\(^\|\/\)[.]\{1,2\}$' | grep -v -e "/proc/" -e "/dev/" | sort > /tmp/test1
./id3 -0 -q "%_p%_f" "$files" 2> /dev/null | grep -v -e "/proc/" -e "/dev/" | sort > /tmp/test2
diff -q /tmp/test1 /tmp/test2 || exit 1
fi
Expand Down

0 comments on commit 56f6ef4

Please sign in to comment.