Skip to content

Commit 28267f3

Browse files
Merge pull request #804 from g-maxime/nodb
CLI: Add option to disable use of the database
2 parents 3a4aa83 + 296f2ae commit 28267f3

File tree

9 files changed

+65
-12
lines changed

9 files changed

+65
-12
lines changed

Source/CLI/CLI.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
124124

125125
//--------------------------------------------------------------------------
126126
CLI::CLI() : watch_folder_user(NULL), use_as_user(-1), use_daemon(false), asynchronous(false),
127-
force_analyze(false), full_report(false), include_hidden_files(false), mil_analyze(true),
127+
force_analyze(false), full_report(false), no_database(false), include_hidden_files(false), mil_analyze(true),
128128
watch_folder_recursive(true), create_policy_mode(false), file_information(false),
129129
plugins_list_mode(false), list_watch_folders_mode(false), no_needs_files_mode(false),
130130
list_mode(false), fixer(false)
@@ -146,6 +146,9 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
146146
return CLI_RETURN_ERROR;
147147
}
148148

149+
if (no_database)
150+
MCL.set_no_database(no_database);
151+
149152
if (!no_needs_files_mode)
150153
{
151154
// If no filenames (and no options)
@@ -1045,6 +1048,12 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S
10451048
force_analyze = force;
10461049
}
10471050

1051+
//--------------------------------------------------------------------------
1052+
void CLI::set_no_database(bool no_db)
1053+
{
1054+
no_database = no_db;
1055+
}
1056+
10481057
//--------------------------------------------------------------------------
10491058
void CLI::set_mil_analyze(bool analyze)
10501059
{

Source/CLI/CLI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace MediaConch
5151
int set_user_to_use(const std::string& user);
5252
int set_compression_mode(const std::string& mode_str);
5353
void set_force_analyze(bool force);
54+
void set_no_database(bool no_db);
5455
void set_mil_analyze(bool analyze);
5556
void set_asynchronous(bool async);
5657
void set_create_policy_mode();
@@ -103,6 +104,7 @@ namespace MediaConch
103104
bool use_daemon;
104105
bool asynchronous;
105106
bool force_analyze;
107+
bool no_database;
106108
bool full_report;
107109
bool include_hidden_files;
108110
bool mil_analyze;

Source/CLI/CommandLine_Parser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ static void change_short_options_to_long(std::string& argument)
163163
argument = "--help=Advanced";
164164
if (argument=="-v")
165165
argument = "--version";
166+
167+
// Main short options
166168
if (argument=="-f")
167169
argument = "--force";
168170
if (argument=="-nmil")
169171
argument = "--nomilanalyze";
172+
if (argument=="-ndb")
173+
argument = "--nodatabase";
170174

171175
// Backward compatibility
172176
if (argument=="-tc")
@@ -272,6 +276,7 @@ int Parse(MediaConch::CLI* cli, std::string& argument)
272276
OPTION("--full", Full)
273277
OPTION("--includehidden", IncludeHidden)
274278
OPTION("--nomilanalyze", NoMilAnalyze)
279+
OPTION("--nodatabase", NoDatabase)
275280
OPTION("--async", Asynchronous)
276281
OPTION("--pluginslist", PluginsList)
277282
OPTION("--useplugin", UsePlugin)
@@ -547,6 +552,14 @@ CL_OPTION(NoMilAnalyze)
547552
return CLI_RETURN_NONE;
548553
}
549554

555+
//---------------------------------------------------------------------------
556+
CL_OPTION(NoDatabase)
557+
{
558+
(void)argument;
559+
cli->set_no_database(true);
560+
return CLI_RETURN_NONE;
561+
}
562+
550563
//---------------------------------------------------------------------------
551564
CL_OPTION(Asynchronous)
552565
{

Source/CLI/CommandLine_Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CL_OPTION(Force);
5151
CL_OPTION(Full);
5252
CL_OPTION(IncludeHidden);
5353
CL_OPTION(NoMilAnalyze);
54+
CL_OPTION(NoDatabase);
5455
CL_OPTION(Asynchronous);
5556
CL_OPTION(UsePlugin);
5657
CL_OPTION(PluginsList);

Source/CLI/Help.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ int Help_Advanced()
193193
TEXTOUT(" Full MediaInfo report (needed by some policies)");
194194
TEXTOUT("--NoMilAnalyze, -nmil");
195195
TEXTOUT(" Do not analyze with MediaInfoLib");
196+
TEXTOUT("--NoDatabase, -ndb");
197+
TEXTOUT(" Do not read or write to the persistant database");
196198
TEXTOUT("--Async=yes, -as");
197199
TEXTOUT(" Analyze asynchronously the files,");
198200
TEXTOUT(" need to launch again the command to have the result");

Source/Common/Core.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Core::Core() : policies(this), reports(this)
7979
watch_folders_manager = new WatchFoldersManager(this);
8080
policies.create_values_from_csv();
8181
compression_mode = MediaConchLib::compression_ZLib;
82+
no_database = false;
8283
}
8384

8485
Core::~Core()
@@ -154,18 +155,21 @@ void Core::load_plugins_configuration()
154155
void Core::load_database()
155156
{
156157
#ifdef HAVE_SQLITE
157-
std::string db_path;
158-
if (!config || config->get("SQLite_Path", db_path) < 0)
159-
db_path = get_database_path();
158+
if (!no_database)
159+
{
160+
std::string db_path;
161+
if (!config || config->get("SQLite_Path", db_path) < 0)
162+
db_path = get_database_path();
160163

161-
db = new SQLLiteReport;
164+
db = new SQLLiteReport;
162165

163-
((Database*)db)->set_database_directory(db_path);
164-
db->set_database_filename(database_name);
165-
if (db->init_report() < 0)
166-
{
167-
delete db;
168-
db = NULL;
166+
((Database*)db)->set_database_directory(db_path);
167+
db->set_database_filename(database_name);
168+
if (db->init_report() < 0)
169+
{
170+
delete db;
171+
db = NULL;
172+
}
169173
}
170174
#endif
171175
if (!db)
@@ -264,6 +268,18 @@ void Core::set_compression_mode(MediaConchLib::compression compress)
264268
compression_mode = compress;
265269
}
266270

271+
//---------------------------------------------------------------------------
272+
void Core::set_no_database(bool ndb)
273+
{
274+
no_database = ndb;
275+
if (db)
276+
{
277+
delete db;
278+
db = NULL;
279+
}
280+
load_database();
281+
}
282+
267283
//---------------------------------------------------------------------------
268284
int Core::get_ui_poll_request() const
269285
{

Source/Common/Core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class Core
164164
void set_implementation_verbosity(const std::string& verbosity);
165165
const std::string& get_implementation_verbosity();
166166
void set_compression_mode(MediaConchLib::compression compress);
167+
void set_no_database(bool no_database);
167168
int get_ui_poll_request() const;
168169
int get_ui_database_path(std::string& path) const;
169170
bool is_using_daemon() const;
@@ -227,8 +228,9 @@ class Core
227228
std::map<std::string, std::string> implementation_options;
228229
Scheduler *scheduler;
229230
PluginsManager *plugins_manager;
230-
WatchFoldersManager *watch_folders_manager;
231+
WatchFoldersManager *watch_folders_manager;
231232
MediaConchLib::compression compression_mode;
233+
bool no_database;
232234

233235
bool has_outcome_fail(const std::string& report);
234236

Source/Common/MediaConchLib.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,13 @@ void MediaConchLib::set_compression_mode(compression compress)
828828
core->set_compression_mode(compress);
829829
}
830830

831+
//---------------------------------------------------------------------------
832+
void MediaConchLib::set_no_database(bool no_database)
833+
{
834+
if (core)
835+
core->set_no_database(no_database);
836+
}
837+
831838
//---------------------------------------------------------------------------
832839
int MediaConchLib::get_ui_poll_request() const
833840
{

Source/Common/MediaConchLib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class MediaConchLib
406406
void load_plugins_configuration();
407407
void set_plugins_configuration_file(const std::string& file);
408408
void set_compression_mode(compression compress);
409+
void set_no_database(bool no_database);
409410
int get_ui_poll_request() const;
410411
int get_ui_database_path(std::string& path) const;
411412

0 commit comments

Comments
 (0)