diff options
-rw-r--r-- | HISTORY | 4 | ||||
-rw-r--r-- | mg_db.c | 21 | ||||
-rw-r--r-- | mg_db.h | 4 | ||||
-rwxr-xr-x | mugglei.c | 26 | ||||
-rw-r--r-- | vdr_menu.c | 4 |
5 files changed, 42 insertions, 17 deletions
@@ -228,3 +228,7 @@ xxxxxxxx: Version 0.1.8-BETA - import items from the setup menu: This is done by a background thread. Those threads are not allowed to access the OSD, so we removed the status messages of the import progress. +- mugglei: import counter counts only successes. +- mugglei: do not change directory to TLD before starting the import. + mugglei has to be started in TLD or below. This way wildcards will + always be expanded as expected. @@ -317,14 +317,8 @@ mgDb::Sync(char * const * path_argv) } unsigned int importcount=0; - chdir(the_setup.ToplevelDir); FTS *fts; FTSENT *ftsent; - if (!path_argv) - { - static char *default_args[] = { ".", 0}; - path_argv = default_args; - } fts = fts_open( path_argv, FTS_LOGICAL, 0); if (fts) { @@ -335,8 +329,8 @@ mgDb::Sync(char * const * path_argv) mgDebug(1,"Importing from %s",ftsent->fts_path); if (!(mode&S_IFREG)) continue; - SyncFile(ftsent->fts_path); - importcount++; + if (SyncFile(ftsent->fts_path)) + importcount++; if (importcount%1000==0) showimportcount(importcount); } @@ -1051,14 +1045,14 @@ mgDb::getGenre1(TagLib::FileRef& f) return m_Genres[genre1]; } -void +bool mgDb::SyncFile(const char *filename) { char *ext = extension(filename); if (strcasecmp(ext,"flac") && strcasecmp(ext,"ogg") && strcasecmp(ext,"mp3")) - return; + return false; if (!strncmp(filename,"./",2)) // strip leading ./ filename += 2; const char *cfilename=filename; @@ -1067,13 +1061,13 @@ mgDb::SyncFile(const char *filename) if (strlen(cfilename)>255) { mgWarning("Length of file exceeds database field capacity: %s", filename); - return; + return false; } TagLib::FileRef f( filename) ; if (f.isNull()) - return; + return false; if (!f.tag()) - return; + return false; mgDebug(2,"Importing %s",filename); TagLib::AudioProperties *ap = f.audioProperties(); get_ID3v2_Tags(filename); @@ -1123,6 +1117,7 @@ mgDb::SyncFile(const char *filename) c_folder3.quoted(),c_folder4.quoted()); } Execute(sql); + return true; } string @@ -177,7 +177,7 @@ class mgDb { virtual void ClearCollection( const string Name); virtual bool CreateCollection( const string Name); - void Sync(char * const * path_argv = 0); + void Sync(char * const * path_argv); virtual bool FieldExists(string table, string field)=0; void LoadMapInto(string sql,map<string,string>*idmap,map<string,string>*valmap); string LoadItemsInto(mgParts& what,vector<mgItem*>& items); @@ -195,7 +195,7 @@ class mgDb { int m_rows; int m_cols; virtual void SyncEnd() {} - void SyncFile(const char *filename); + bool SyncFile(const char *filename); bool m_database_found; bool m_hasfolderfields; bool m_separate_thread; @@ -63,6 +63,23 @@ const char *I18nTranslate(const char *s,const char *Plugin) return s; } +bool +path_within_tld() +{ + char path[5000]; + if (!getcwd(path,4999)) + { + std::cout << "Path too long" << std::endl; + exit (1); + } + int tldlen = strlen(the_setup.ToplevelDir); + strcat(path,"/"); + int pathlen = strlen(path); + if (pathlen<tldlen) + return false; + return !strncmp(path,the_setup.ToplevelDir,tldlen); +} + int main( int argc, char *argv[] ) { the_setup.SetMugglei(); @@ -83,10 +100,17 @@ int main( int argc, char *argv[] ) std::cout << "Options:" << std::endl; std::cout << the_setup.HelpText(); - exit( 1 ); + exit( 2 ); } the_setup.ProcessArguments(argc,argv); + + if (!path_within_tld()) + { + std::cout << "you should be in " << the_setup.ToplevelDir + << " or below" << std::endl; + exit( 2 ); + } if (optind<argc) { mgDb *sync = GenerateDB(); @@ -1216,6 +1216,8 @@ import() mgThreadSync *s = mgThreadSync::get_instance(); if (!s) return false; - s->Sync(); + static char *tld_arg[] = { 0, 0}; + tld_arg[0] = the_setup.ToplevelDir; + s->Sync(tld_arg); return true; } |