mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-24 05:28:04 +08:00
check_copy function
This commit is contained in:
parent
f7e06ded67
commit
a68ede6f2d
@ -67,6 +67,9 @@ extern std::error_code rename_file(const std::string &from, const std::string &t
|
|||||||
// Copy a file, adjust the access attributes, so that the target is writable.
|
// Copy a file, adjust the access attributes, so that the target is writable.
|
||||||
extern int copy_file(const std::string &from, const std::string &to);
|
extern int copy_file(const std::string &from, const std::string &to);
|
||||||
|
|
||||||
|
// Compares two files, returns 0 if identical.
|
||||||
|
extern int check_copy(const std::string& origin, const std::string& copy);
|
||||||
|
|
||||||
// Ignore system and hidden files, which may be created by the DropBox synchronisation process.
|
// Ignore system and hidden files, which may be created by the DropBox synchronisation process.
|
||||||
// https://github.com/prusa3d/PrusaSlicer/issues/1298
|
// https://github.com/prusa3d/PrusaSlicer/issues/1298
|
||||||
extern bool is_plain_file(const boost::filesystem::directory_entry &path);
|
extern bool is_plain_file(const boost::filesystem::directory_entry &path);
|
||||||
|
@ -436,8 +436,29 @@ int copy_file(const std::string &from, const std::string &to)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
boost::filesystem::permissions(target, perms, ec);
|
boost::filesystem::permissions(target, perms, ec);
|
||||||
|
return -1;
|
||||||
|
return check_copy(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
int check_copy(const std::string &origin, const std::string ©)
|
||||||
|
{
|
||||||
|
std::ifstream f1(origin, std::ifstream::binary | std::ifstream::ate);
|
||||||
|
std::ifstream f2(copy, std::ifstream::binary | std::ifstream::ate);
|
||||||
|
|
||||||
|
if (f1.fail() || f2.fail()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f1.tellg() != f2.tellg()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f1.seekg(0, std::ifstream::beg);
|
||||||
|
f2.seekg(0, std::ifstream::beg);
|
||||||
|
bool ident = std::equal(std::istreambuf_iterator<char>(f1.rdbuf()),
|
||||||
|
std::istreambuf_iterator<char>(),
|
||||||
|
std::istreambuf_iterator<char>(f2.rdbuf()));
|
||||||
|
return(ident ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore system and hidden files, which may be created by the DropBox synchronisation process.
|
// Ignore system and hidden files, which may be created by the DropBox synchronisation process.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user