|
|
|
@ -1975,20 +1975,19 @@ namespace {
|
|
|
|
|
std::string path = newPath;
|
|
|
|
|
auto oldFsPath = fs::path(path);
|
|
|
|
|
std::string format = Params::instance().format_;
|
|
|
|
|
replace(format, ":basename:", p.stem().string());
|
|
|
|
|
replace(format, ":dirname:", p.parent_path().filename().string());
|
|
|
|
|
replace(format, ":basename:", p.stem().string());
|
|
|
|
|
replace(format, ":dirname:", p.parent_path().filename().string());
|
|
|
|
|
replace(format, ":parentname:", p.parent_path().parent_path().filename().string());
|
|
|
|
|
|
|
|
|
|
const size_t max = 1024;
|
|
|
|
|
char basename[max];
|
|
|
|
|
std::memset(basename, 0x0, max);
|
|
|
|
|
if (strftime(basename, max, format.c_str(), tm) == 0) {
|
|
|
|
|
std::cerr << _("Filename format yields empty filename for the file") << " "
|
|
|
|
|
<< path << "\n";
|
|
|
|
|
std::cerr << _("Filename format yields empty filename for the file") << " " << path << "\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newPath = p.parent_path() / (basename + p.extension().string());
|
|
|
|
|
newPath = (p.parent_path() / (basename + p.extension().string())).string();
|
|
|
|
|
p = fs::path(newPath);
|
|
|
|
|
|
|
|
|
|
if (p.parent_path() == oldFsPath.parent_path() && p.filename() == oldFsPath.filename()) {
|
|
|
|
@ -2001,44 +2000,40 @@ namespace {
|
|
|
|
|
bool go = true;
|
|
|
|
|
int seq = 1;
|
|
|
|
|
std::string s;
|
|
|
|
|
Params::FileExistsPolicy fileExistsPolicy
|
|
|
|
|
= Params::instance().fileExistsPolicy_;
|
|
|
|
|
Params::FileExistsPolicy fileExistsPolicy = Params::instance().fileExistsPolicy_;
|
|
|
|
|
while (go) {
|
|
|
|
|
if (Exiv2::fileExists(newPath)) {
|
|
|
|
|
switch (fileExistsPolicy) {
|
|
|
|
|
case Params::overwritePolicy:
|
|
|
|
|
go = false;
|
|
|
|
|
break;
|
|
|
|
|
case Params::renamePolicy:
|
|
|
|
|
newPath = p.parent_path() / (std::string(basename) + "_"
|
|
|
|
|
+ Exiv2::toString(seq++)
|
|
|
|
|
+ p.extension().string());
|
|
|
|
|
break;
|
|
|
|
|
case Params::askPolicy:
|
|
|
|
|
std::cout << Params::instance().progname()
|
|
|
|
|
<< ": " << _("File") << " `" << newPath
|
|
|
|
|
<< "' " << _("exists. [O]verwrite, [r]ename or [s]kip?")
|
|
|
|
|
<< " ";
|
|
|
|
|
std::cin >> s;
|
|
|
|
|
switch (s.at(0)) {
|
|
|
|
|
case 'o':
|
|
|
|
|
case 'O':
|
|
|
|
|
case Params::overwritePolicy:
|
|
|
|
|
go = false;
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
case 'R':
|
|
|
|
|
fileExistsPolicy = Params::renamePolicy;
|
|
|
|
|
newPath = p.parent_path() / (std::string(basename) + "_"
|
|
|
|
|
+ Exiv2::toString(seq++)
|
|
|
|
|
+ p.extension().string());
|
|
|
|
|
case Params::renamePolicy:
|
|
|
|
|
newPath = (p.parent_path() /
|
|
|
|
|
(std::string(basename) + "_" + Exiv2::toString(seq++) + p.extension().string()))
|
|
|
|
|
.string();
|
|
|
|
|
break;
|
|
|
|
|
default: // skip
|
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Params::askPolicy:
|
|
|
|
|
std::cout << Params::instance().progname() << ": " << _("File") << " `" << newPath << "' "
|
|
|
|
|
<< _("exists. [O]verwrite, [r]ename or [s]kip?") << " ";
|
|
|
|
|
std::cin >> s;
|
|
|
|
|
switch (s.at(0)) {
|
|
|
|
|
case 'o':
|
|
|
|
|
case 'O':
|
|
|
|
|
go = false;
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
case 'R':
|
|
|
|
|
fileExistsPolicy = Params::renamePolicy;
|
|
|
|
|
newPath = (p.parent_path() / (std::string(basename) + "_" + Exiv2::toString(seq++) +
|
|
|
|
|
p.extension().string()))
|
|
|
|
|
.string();
|
|
|
|
|
break;
|
|
|
|
|
default: // skip
|
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
go = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -2054,15 +2049,13 @@ namespace {
|
|
|
|
|
// Workaround for MinGW rename which does not overwrite existing files
|
|
|
|
|
remove(newPath.c_str());
|
|
|
|
|
if (std::rename(path.c_str(), newPath.c_str()) == -1) {
|
|
|
|
|
std::cerr << Params::instance().progname()
|
|
|
|
|
<< ": " << _("Failed to rename") << " "
|
|
|
|
|
<< path << " " << _("to") << " " << newPath << ": "
|
|
|
|
|
<< Exiv2::strError() << "\n";
|
|
|
|
|
std::cerr << Params::instance().progname() << ": " << _("Failed to rename") << " " << path << " " << _("to")
|
|
|
|
|
<< " " << newPath << ": " << Exiv2::strError() << "\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
} // renameFile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string newFilePath(const std::string& path, const std::string& ext)
|
|
|
|
|
{
|
|
|
|
@ -2072,7 +2065,7 @@ namespace {
|
|
|
|
|
directory = p.parent_path();
|
|
|
|
|
if (Exiv2::fileProtocol(path) != Exiv2::pFile)
|
|
|
|
|
directory.clear(); // use current directory for remote files
|
|
|
|
|
return directory / (p.stem().string() + ext);
|
|
|
|
|
return (directory / (p.stem().string() + ext)).string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int dontOverwrite(const std::string& path)
|
|
|
|
|