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