Merge pull request #664 from cryptoknight/WriteOnCopy

Don't automatically make copied files writable on Windows
This commit is contained in:
Aleksandar Fabijanic 2015-01-16 15:33:32 -06:00
commit 4e6fad87dc
4 changed files with 68 additions and 78 deletions

View File

@ -288,12 +288,8 @@ void FileImpl::copyToImpl(const std::string& path) const
{
poco_assert (!_path.empty());
if (CopyFileA(_path.c_str(), path.c_str(), FALSE) != 0)
{
FileImpl copy(path);
copy.setWriteableImpl(true);
}
else handleLastErrorImpl(_path);
if (CopyFileA(_path.c_str(), path.c_str(), FALSE) == 0)
handleLastErrorImpl(_path);
}

View File

@ -294,12 +294,8 @@ void FileImpl::copyToImpl(const std::string& path) const
std::wstring upath;
UnicodeConverter::toUTF16(path, upath);
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) != 0)
{
FileImpl copy(path);
copy.setWriteableImpl(true);
}
else handleLastErrorImpl(_path);
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) == 0)
handleLastErrorImpl(_path);
}

View File

@ -285,12 +285,8 @@ void FileImpl::copyToImpl(const std::string& path) const
std::wstring upath;
UnicodeConverter::toUTF16(path, upath);
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) != 0)
{
FileImpl copy(path);
copy.setWriteableImpl(true);
}
else handleLastErrorImpl(_path);
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) == 0)
handleLastErrorImpl(_path);
}

View File

@ -372,9 +372,11 @@ void FileTest::testCopy()
File f1("testfile.dat");
TemporaryFile f2;
f1.copyTo(f2.path());
f1.setReadOnly().copyTo(f2.path());
assert (f2.exists());
assert (!f2.canWrite());
assert (f1.getSize() == f2.getSize());
f1.setWriteable().remove();
}