Skip to content

Commit

Permalink
First prune_raw working version
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Burman <yanburman@users.noreply.github.com>
  • Loading branch information
yanburman committed Jul 7, 2016
1 parent f543491 commit 9a88a49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Added prune_raw utility to delete RAW/JPEG files that don't have a matching DNG file

v1.0.1
* Support for Mac OSX
* Support for Windows 32-bit builds
Expand Down
37 changes: 32 additions & 5 deletions src/prune_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "FileFinder.h"
#include "utils.h"
#include "helpers.h"

static int handle_arg(const char *arg, FileFinder &finder)
{
Expand Down Expand Up @@ -53,12 +54,38 @@ static int do_prune(const std::vector<RawWorkItem *> &o_WorkItems, std::list<std
{
std::vector<RawWorkItem *>::const_iterator it;

for (it = o_WorkItems.begin(); it != o_WorkItems.end(); ++it)
printf("Found: %s, %s\n", (*it)->m_szRawFile.c_str(), (*it)->m_szMetadataFile.c_str());
for (it = o_WorkItems.begin(); it != o_WorkItems.end(); ++it) {
const std::string &szRawFile = (*it)->m_szRawFile;
size_t unDotIndex = szRawFile.find_last_of('.');
if (unDotIndex == std::string::npos) {
printf("Encountered an internal error. Refusing to continue!\n");
return -1;
}

size_t unDelimIndex = szRawFile.find_last_of(DELIM);
if (unDelimIndex == std::string::npos)
unDelimIndex = 0;
else
++unDelimIndex;

std::string szDngFilename = szRawFile.substr(unDelimIndex, unDotIndex - unDelimIndex) + dng_suffix;

bool found = false;
std::list<std::string>::iterator dng_it;
for (dng_it = files.begin(); dng_it != files.end(); ++dng_it) {
if (*dng_it == szDngFilename) {
files.erase(dng_it);
found = true;
break;
}
}

std::list<std::string>::const_iterator dng_it;
for (dng_it = files.begin(); dng_it != files.end(); ++dng_it)
printf("Found DNG: %s\n", dng_it->c_str());
if (!found) {
printf("Removing: %s, %s\n", (*it)->m_szRawFile.c_str(), (*it)->m_szMetadataFile.c_str());
remove((*it)->m_szRawFile.c_str());
remove((*it)->m_szMetadataFile.c_str());
}
}

return 0;
}
Expand Down

0 comments on commit 9a88a49

Please sign in to comment.