Remove the last safe directory listing functions.
This commit is contained in:
@@ -676,22 +676,31 @@ rtengine::ProcessingJob* BatchQueue::imageReady (rtengine::IImage16* img)
|
||||
|
||||
if (saveBatchQueue ()) {
|
||||
::g_remove (processedParams.c_str ());
|
||||
// Delete all files in directory \batch when finished, just to be sure to remove zombies
|
||||
|
||||
// Not sure that locking is necessary, but it should be safer
|
||||
MYREADERLOCK(l, entryRW);
|
||||
// Delete all files in directory batch when finished, just to be sure to remove zombies
|
||||
auto isEmpty = false;
|
||||
|
||||
if( fd.empty() ) {
|
||||
MYREADERLOCK_RELEASE(l);
|
||||
{
|
||||
#if PROTECT_VECTORS
|
||||
MYREADERLOCK(l, entryRW);
|
||||
#endif
|
||||
isEmpty = fd.empty();
|
||||
}
|
||||
|
||||
std::vector<Glib::ustring> names;
|
||||
Glib::ustring batchdir = Glib::build_filename(options.rtdir, "batch");
|
||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path (batchdir);
|
||||
safe_build_file_list (dir, names, batchdir);
|
||||
if (isEmpty) {
|
||||
|
||||
for (auto iter = names.begin (); iter != names.end (); ++iter) {
|
||||
::g_remove (iter->c_str ());
|
||||
}
|
||||
const auto batchdir = Glib::build_filename (options.rtdir, "batch");
|
||||
|
||||
try {
|
||||
|
||||
auto dir = Gio::File::create_for_path (batchdir);
|
||||
auto enumerator = dir->enumerate_children ("standard::name");
|
||||
|
||||
while (auto file = enumerator->next_file ()) {
|
||||
::g_remove (Glib::build_filename (batchdir, file->get_name ()).c_str ());
|
||||
}
|
||||
|
||||
} catch (Glib::Exception&) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -542,11 +542,44 @@ void FileCatalog::closeDir ()
|
||||
|
||||
std::vector<Glib::ustring> FileCatalog::getFileList ()
|
||||
{
|
||||
|
||||
std::vector<Glib::ustring> names;
|
||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path (selectedDirectory);
|
||||
safe_build_file_list (dir, names, selectedDirectory, &(options.parsedExtensions));
|
||||
// Issue 2406 std::sort (names.begin(), names.end());
|
||||
|
||||
std::set<Glib::ustring> extensions;
|
||||
for (const auto& parsedExt : options.parsedExtensions) {
|
||||
extensions.emplace (parsedExt.lowercase ());
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
auto dir = Gio::File::create_for_path (selectedDirectory);
|
||||
|
||||
auto enumerator = dir->enumerate_children ();
|
||||
|
||||
while (auto file = enumerator->next_file ()) {
|
||||
|
||||
const Glib::ustring fname = file->get_name ();
|
||||
|
||||
auto lastdot = fname.find_last_of ('.');
|
||||
if (lastdot >= fname.length () - 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto fext = fname.substr (lastdot + 1).lowercase ();
|
||||
if (extensions.count (fext) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.emplace_back (Glib::build_filename (selectedDirectory, fname));
|
||||
}
|
||||
|
||||
} catch (Glib::Exception& exception) {
|
||||
|
||||
if (options.rtSettings.verbose) {
|
||||
std::cerr << "Failed to list directory \"" << selectedDirectory << "\": " << exception.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
|
||||
@@ -497,39 +497,54 @@ int processLineParams( int argc, char **argv )
|
||||
break;
|
||||
|
||||
case 'c': // MUST be last option
|
||||
while( iArg + 1 < argc ) {
|
||||
while (iArg + 1 < argc) {
|
||||
iArg++;
|
||||
|
||||
if( !safe_file_test( safe_filename_to_utf8(argv[iArg]), Glib::FILE_TEST_EXISTS )) {
|
||||
std::cerr << argv[iArg] << " doesn't exist." << std::endl;
|
||||
const auto argument = safe_filename_to_utf8 (argv[iArg]);
|
||||
|
||||
if (Glib::file_test (argument, Glib::FILE_TEST_IS_REGULAR)) {
|
||||
inputFiles.emplace_back (argument);
|
||||
continue;
|
||||
}
|
||||
|
||||
if( safe_file_test( safe_filename_to_utf8(argv[iArg]), Glib::FILE_TEST_IS_DIR )) {
|
||||
std::vector<Glib::ustring> names;
|
||||
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path ( argv[iArg] );
|
||||
safe_build_file_list (dir, names, argv[iArg] );
|
||||
if (Glib::file_test (argument, Glib::FILE_TEST_IS_DIR)) {
|
||||
|
||||
for(size_t iFile = 0; iFile < names.size(); iFile++ ) {
|
||||
if( !safe_file_test( names[iFile] , Glib::FILE_TEST_IS_DIR)) {
|
||||
// skip files without extension and without sidecar files
|
||||
Glib::ustring s(names[iFile]);
|
||||
Glib::ustring::size_type ext = s.find_last_of('.');
|
||||
|
||||
if( Glib::ustring::npos == ext ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( ! s.substr(ext).compare( paramFileExtension )) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inputFiles.push_back( names[iFile] );
|
||||
}
|
||||
auto dir = Gio::File::create_for_path (argument);
|
||||
if (!dir || !dir->query_exists()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
inputFiles.push_back( safe_filename_to_utf8 (argv[iArg]) );
|
||||
|
||||
try {
|
||||
|
||||
auto enumerator = dir->enumerate_children ();
|
||||
|
||||
while (auto file = enumerator->next_file ()) {
|
||||
|
||||
const auto fileName = Glib::build_filename (argument, file->get_name ());
|
||||
|
||||
if (Glib::file_test (fileName, Glib::FILE_TEST_IS_DIR)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip files without extension and sidecar files
|
||||
auto lastdot = fileName.find_last_of('.');
|
||||
if (lastdot == Glib::ustring::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fileName.substr (lastdot).compare (paramFileExtension) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inputFiles.emplace_back (fileName);
|
||||
}
|
||||
|
||||
} catch (Glib::Exception&) {}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cerr << "\"" << argument << "\" is neither a regular file nor a directory." << std::endl;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user