test/DumpDatabase: use AtScopeExit()
This commit is contained in:
parent
6fd7d8191e
commit
6190da1300
|
@ -34,6 +34,7 @@
|
||||||
#include "event/Loop.hxx"
|
#include "event/Loop.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
#include "util/ScopeExit.hxx"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
@ -108,6 +109,7 @@ try {
|
||||||
/* initialize MPD */
|
/* initialize MPD */
|
||||||
|
|
||||||
config_global_init();
|
config_global_init();
|
||||||
|
AtScopeExit() { config_global_finish(); };
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
ReadConfigFile(config_path);
|
ReadConfigFile(config_path);
|
||||||
|
@ -132,29 +134,23 @@ try {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AtScopeExit(db) { delete db; };
|
||||||
|
|
||||||
if (!db->Open(error)) {
|
if (!db->Open(error)) {
|
||||||
delete db;
|
|
||||||
cerr << error.GetMessage() << endl;
|
cerr << error.GetMessage() << endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AtScopeExit(db) { db->Close(); };
|
||||||
|
|
||||||
const DatabaseSelection selection("", true);
|
const DatabaseSelection selection("", true);
|
||||||
|
|
||||||
if (!db->Visit(selection, DumpDirectory, DumpSong, DumpPlaylist,
|
if (!db->Visit(selection, DumpDirectory, DumpSong, DumpPlaylist,
|
||||||
error)) {
|
error)) {
|
||||||
db->Close();
|
|
||||||
delete db;
|
|
||||||
cerr << error.GetMessage() << endl;
|
cerr << error.GetMessage() << endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
db->Close();
|
|
||||||
delete db;
|
|
||||||
|
|
||||||
/* deinitialize everything */
|
|
||||||
|
|
||||||
config_global_finish();
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
LogError(e);
|
LogError(e);
|
||||||
|
|
Loading…
Reference in New Issue