mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 22:31:23 +01:00
Don't automatically mark copied files as writable on Windows
This commit is contained in:
parent
d992509f6e
commit
fc24be6199
@ -35,17 +35,17 @@ public:
|
||||
FileImpl::handleLastErrorImpl(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
~FileHandle()
|
||||
{
|
||||
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
||||
}
|
||||
|
||||
|
||||
HANDLE get() const
|
||||
{
|
||||
return _h;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
HANDLE _h;
|
||||
};
|
||||
@ -116,7 +116,7 @@ bool FileImpl::existsImpl() const
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
@ -135,7 +135,7 @@ bool FileImpl::canReadImpl() const
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||
handleLastErrorImpl(_path);
|
||||
@ -205,7 +205,7 @@ Timestamp FileImpl::createdImpl() const
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
||||
}
|
||||
@ -216,7 +216,7 @@ Timestamp FileImpl::getLastModifiedImpl() const
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
||||
}
|
||||
@ -243,7 +243,7 @@ FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
LARGE_INTEGER li;
|
||||
li.LowPart = fad.nFileSizeLow;
|
||||
@ -261,12 +261,12 @@ void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
li.QuadPart = size;
|
||||
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||
handleLastErrorImpl(_path);
|
||||
if (SetEndOfFile(fh.get()) == 0)
|
||||
if (SetEndOfFile(fh.get()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -309,7 +305,7 @@ void FileImpl::renameToImpl(const std::string& path)
|
||||
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
@ -320,7 +316,7 @@ void FileImpl::removeImpl()
|
||||
|
||||
if (isDirectoryImpl())
|
||||
{
|
||||
if (RemoveDirectoryW(_upath.c_str()) == 0)
|
||||
if (RemoveDirectoryW(_upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
else
|
||||
@ -352,7 +348,7 @@ bool FileImpl::createFileImpl()
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
if (CreateDirectoryW(_upath.c_str(), 0) == 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user