294 |
294 |
bool md5sum(const fs::path &path, md5digest &digest)
|
295 |
295 |
{
|
296 |
296 |
try {
|
297 |
|
Exiv2::FileIo io(path.file_string());
|
|
297 |
Exiv2::FileIo io(path.string());
|
298 |
298 |
if (io.open() != 0)
|
299 |
299 |
return false;
|
300 |
300 |
Exiv2::IoCloser closer(io);
|
... | ... | |
568 |
568 |
|
569 |
569 |
fs::path uniquify(const fs::path &dest)
|
570 |
570 |
{
|
571 |
|
std::string ext = dest.extension();
|
572 |
|
std::string fname = dest.stem();
|
|
571 |
std::string ext = dest.extension().string();
|
|
572 |
std::string fname = dest.stem().string();
|
573 |
573 |
fs::path parent = dest.parent_path();
|
574 |
574 |
|
575 |
575 |
unsigned number = 1;
|
... | ... | |
600 |
600 |
std::vector<std::string>::const_iterator x_iter = params.excludes.begin();
|
601 |
601 |
std::vector<std::string>::const_iterator x_end = params.excludes.end();
|
602 |
602 |
for( ; x_iter != x_end; ++x_iter ) {
|
603 |
|
if(boost::contains(directory.file_string(), *x_iter)) {
|
|
603 |
if(boost::contains(directory.string(), *x_iter)) {
|
604 |
604 |
exclude = true;
|
605 |
605 |
break;
|
606 |
606 |
}
|
607 |
607 |
}
|
608 |
608 |
if(exclude) {
|
609 |
|
info(std::string("excluding directory: ") + directory.file_string() +
|
|
609 |
info(std::string("excluding directory: ") + directory.string() +
|
610 |
610 |
" matched: " + *x_iter);
|
611 |
611 |
++params.dir_ex_count;
|
612 |
612 |
return;
|
... | ... | |
621 |
621 |
process_directory(p_iter->path(), depth + 1, params);
|
622 |
622 |
else {
|
623 |
623 |
info(std::string("depth reached, skipping: ") +
|
624 |
|
p_iter->path().file_string());
|
|
624 |
p_iter->path().string());
|
625 |
625 |
}
|
626 |
626 |
}
|
627 |
627 |
else if( is_regular_file(*p_iter) ) {
|
... | ... | |
630 |
630 |
exclude = false;
|
631 |
631 |
x_iter = params.excludes.begin();
|
632 |
632 |
for( ; x_iter != x_end; ++x_iter ) {
|
633 |
|
if(boost::contains(p_iter->path().file_string(), *x_iter)) {
|
|
633 |
if(boost::contains(p_iter->path().string(), *x_iter)) {
|
634 |
634 |
exclude = true;
|
635 |
635 |
break;
|
636 |
636 |
}
|
637 |
637 |
}
|
638 |
638 |
if(exclude) {
|
639 |
|
info(std::string("excluding file: ") + p_iter->path().file_string() +
|
|
639 |
info(std::string("excluding file: ") + p_iter->path().string() +
|
640 |
640 |
" matched: " + *x_iter);
|
641 |
641 |
++params.file_ex_count;
|
642 |
642 |
continue;
|
... | ... | |
648 |
648 |
if(!dest_subdir.empty())
|
649 |
649 |
dest_file = params.dest_dir / dest_subdir;
|
650 |
650 |
else if(params.ignore_unsorted) {
|
651 |
|
info(std::string("ignoring unsorted: ") + p_iter->path().file_string());
|
|
651 |
info(std::string("ignoring unsorted: ") + p_iter->path().string());
|
652 |
652 |
++params.unsorted_ignored_count;
|
653 |
653 |
continue;
|
654 |
654 |
}
|
655 |
655 |
else {
|
656 |
|
info(std::string("unsorted file (missing metadata): ") + p_iter->path().file_string());
|
|
656 |
info(std::string("unsorted file (missing metadata): ") + p_iter->path().string());
|
657 |
657 |
dest_file = params.unsorted_dir;
|
658 |
658 |
++params.unsorted_count;
|
659 |
659 |
}
|
660 |
660 |
|
661 |
|
dest_file /= p_iter->filename();
|
|
661 |
dest_file /= p_iter->path().filename();
|
662 |
662 |
|
663 |
663 |
if(fs::exists(dest_file)) {
|
664 |
664 |
if(params.ignore_dups) {
|
665 |
|
info(std::string("ignoring: ") + p_iter->path().file_string() +
|
666 |
|
" duplicates: " + dest_file.file_string());
|
|
665 |
info(std::string("ignoring: ") + p_iter->path().string() +
|
|
666 |
" duplicates: " + dest_file.string());
|
667 |
667 |
++params.dups_ignored_count;
|
668 |
668 |
continue;
|
669 |
669 |
}
|
670 |
670 |
else {
|
671 |
671 |
if(params.force) {
|
672 |
|
info(std::string("force removing: ") + dest_file.file_string() + " for: "
|
673 |
|
+ p_iter->path().file_string());
|
|
672 |
info(std::string("force removing: ") + dest_file.string() + " for: "
|
|
673 |
+ p_iter->path().string());
|
674 |
674 |
if(!params.dry_run)
|
675 |
675 |
fs::remove(dest_file);
|
676 |
676 |
}
|
677 |
677 |
else if(params.rename) {
|
678 |
|
info(std::string("renaming: ") + p_iter->path().file_string() +
|
679 |
|
" duplicates: " + dest_file.file_string());
|
|
678 |
info(std::string("renaming: ") + p_iter->path().string() +
|
|
679 |
" duplicates: " + dest_file.string());
|
680 |
680 |
dest_file = uniquify(dest_file);
|
681 |
681 |
}
|
682 |
682 |
else {
|
683 |
|
info(std::string("duplicate file: ") + p_iter->path().file_string() +
|
684 |
|
" of: " + dest_file.file_string());
|
685 |
|
dest_file = params.dups_dir / dest_subdir / p_iter->filename();
|
|
683 |
info(std::string("duplicate file: ") + p_iter->path().string() +
|
|
684 |
" of: " + dest_file.string());
|
|
685 |
dest_file = params.dups_dir / dest_subdir / p_iter->path().filename();
|
686 |
686 |
// Ugh, more dup possibilities
|
687 |
687 |
if(fs::exists(dest_file)) {
|
688 |
|
info(std::string("renaming: ") + p_iter->path().file_string() +
|
689 |
|
" duplicates: " + dest_file.file_string());
|
|
688 |
info(std::string("renaming: ") + p_iter->path().string() +
|
|
689 |
" duplicates: " + dest_file.string());
|
690 |
690 |
dest_file = uniquify(dest_file);
|
691 |
691 |
}
|
692 |
692 |
}
|
... | ... | |
698 |
698 |
fs::create_directories(dest_file.parent_path());
|
699 |
699 |
|
700 |
700 |
if(params.symlink) {
|
701 |
|
info(std::string("linking from: ") + p_iter->path().file_string() +
|
702 |
|
" to: " + dest_file.file_string());
|
|
701 |
info(std::string("linking from: ") + p_iter->path().string() +
|
|
702 |
" to: " + dest_file.string());
|
703 |
703 |
if(!params.dry_run) {
|
704 |
704 |
// The target of a symlink must be either absolute (aka complete) or
|
705 |
705 |
// relative to the location of the link. Easiest solution is to make
|
... | ... | |
713 |
713 |
}
|
714 |
714 |
}
|
715 |
715 |
else {
|
716 |
|
info(std::string("copying from: ") + p_iter->path().file_string() +
|
717 |
|
" to: " + dest_file.file_string());
|
|
716 |
info(std::string("copying from: ") + p_iter->path().string() +
|
|
717 |
" to: " + dest_file.string());
|
718 |
718 |
if(!params.dry_run) {
|
719 |
719 |
// Copy the file and restore its write time (needed for posix)
|
720 |
720 |
std::time_t time = fs::last_write_time(*p_iter);
|
... | ... | |
730 |
730 |
if(!ok) {
|
731 |
731 |
// Should probably find a more appropriate exception for this
|
732 |
732 |
throw std::runtime_error(std::string("File verification failed: '")
|
733 |
|
+ p_iter->path().file_string() + "' differs from '" +
|
734 |
|
dest_file.file_string() + "'");
|
|
733 |
+ p_iter->path().string() + "' differs from '" +
|
|
734 |
dest_file.string() + "'");
|
735 |
735 |
}
|
736 |
736 |
else {
|
737 |
737 |
info(std::string("verification passed"));
|
... | ... | |
740 |
740 |
}
|
741 |
741 |
}
|
742 |
742 |
if(params.move) {
|
743 |
|
info(std::string("removing: ") + p_iter->path().file_string());
|
|
743 |
info(std::string("removing: ") + p_iter->path().string());
|
744 |
744 |
if(!params.dry_run)
|
745 |
745 |
fs::remove(*p_iter);
|
746 |
746 |
}
|
... | ... | |
752 |
752 |
++params.ok_count;
|
753 |
753 |
}
|
754 |
754 |
catch(fs::filesystem_error& e) {
|
755 |
|
error(e, std::string("skipping file: " + p_iter->path().file_string()));
|
|
755 |
error(e, std::string("skipping file: " + p_iter->path().string()));
|
756 |
756 |
++params.file_err_count;
|
757 |
757 |
}
|
758 |
758 |
}
|
759 |
759 |
}
|
760 |
760 |
}
|
761 |
761 |
catch(fs::filesystem_error& e) {
|
762 |
|
error(e, std::string("skipping directory: " + directory.file_string()));
|
|
762 |
error(e, std::string("skipping directory: " + directory.string()));
|
763 |
763 |
++params.dir_err_count;
|
764 |
764 |
}
|
765 |
765 |
}
|