mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
Don't automatically mark copied files as writable on Windows (non-Unicode and CE)
This commit is contained in:
@@ -34,17 +34,17 @@ public:
|
|||||||
FileImpl::handleLastErrorImpl(path);
|
FileImpl::handleLastErrorImpl(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~FileHandle()
|
~FileHandle()
|
||||||
{
|
{
|
||||||
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE get() const
|
HANDLE get() const
|
||||||
{
|
{
|
||||||
return _h;
|
return _h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HANDLE _h;
|
HANDLE _h;
|
||||||
};
|
};
|
||||||
@@ -112,7 +112,7 @@ bool FileImpl::existsImpl() const
|
|||||||
bool FileImpl::canReadImpl() const
|
bool FileImpl::canReadImpl() const
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
DWORD attr = GetFileAttributes(_path.c_str());
|
DWORD attr = GetFileAttributes(_path.c_str());
|
||||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
@@ -131,7 +131,7 @@ bool FileImpl::canReadImpl() const
|
|||||||
bool FileImpl::canWriteImpl() const
|
bool FileImpl::canWriteImpl() const
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
DWORD attr = GetFileAttributes(_path.c_str());
|
DWORD attr = GetFileAttributes(_path.c_str());
|
||||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
@@ -201,7 +201,7 @@ Timestamp FileImpl::createdImpl() const
|
|||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||||
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ Timestamp FileImpl::getLastModifiedImpl() const
|
|||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||||
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
|||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||||
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
li.LowPart = fad.nFileSizeLow;
|
li.LowPart = fad.nFileSizeLow;
|
||||||
@@ -257,7 +257,7 @@ void FileImpl::setSizeImpl(FileSizeImpl size)
|
|||||||
li.QuadPart = size;
|
li.QuadPart = size;
|
||||||
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
if (SetEndOfFile(fh.get()) == 0)
|
if (SetEndOfFile(fh.get()) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,12 +288,8 @@ void FileImpl::copyToImpl(const std::string& path) const
|
|||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
if (CopyFileA(_path.c_str(), path.c_str(), FALSE) != 0)
|
if (CopyFileA(_path.c_str(), path.c_str(), FALSE) == 0)
|
||||||
{
|
handleLastErrorImpl(_path);
|
||||||
FileImpl copy(path);
|
|
||||||
copy.setWriteableImpl(true);
|
|
||||||
}
|
|
||||||
else handleLastErrorImpl(_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -301,7 +297,7 @@ void FileImpl::renameToImpl(const std::string& path)
|
|||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
if (MoveFileA(_path.c_str(), path.c_str()) == 0)
|
if (MoveFileA(_path.c_str(), path.c_str()) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +308,7 @@ void FileImpl::removeImpl()
|
|||||||
|
|
||||||
if (isDirectoryImpl())
|
if (isDirectoryImpl())
|
||||||
{
|
{
|
||||||
if (RemoveDirectoryA(_path.c_str()) == 0)
|
if (RemoveDirectoryA(_path.c_str()) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -344,7 +340,7 @@ bool FileImpl::createFileImpl()
|
|||||||
bool FileImpl::createDirectoryImpl()
|
bool FileImpl::createDirectoryImpl()
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
if (existsImpl() && isDirectoryImpl())
|
if (existsImpl() && isDirectoryImpl())
|
||||||
return false;
|
return false;
|
||||||
if (CreateDirectoryA(_path.c_str(), 0) == 0)
|
if (CreateDirectoryA(_path.c_str(), 0) == 0)
|
||||||
|
|||||||
@@ -36,17 +36,17 @@ public:
|
|||||||
FileImpl::handleLastErrorImpl(path);
|
FileImpl::handleLastErrorImpl(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~FileHandle()
|
~FileHandle()
|
||||||
{
|
{
|
||||||
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE get() const
|
HANDLE get() const
|
||||||
{
|
{
|
||||||
return _h;
|
return _h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HANDLE _h;
|
HANDLE _h;
|
||||||
};
|
};
|
||||||
@@ -117,7 +117,7 @@ bool FileImpl::existsImpl() const
|
|||||||
bool FileImpl::canReadImpl() const
|
bool FileImpl::canReadImpl() const
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
@@ -136,7 +136,7 @@ bool FileImpl::canReadImpl() const
|
|||||||
bool FileImpl::canWriteImpl() const
|
bool FileImpl::canWriteImpl() const
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||||
if (attr == INVALID_FILE_ATTRIBUTES)
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
@@ -196,7 +196,7 @@ Timestamp FileImpl::createdImpl() const
|
|||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ Timestamp FileImpl::getLastModifiedImpl() const
|
|||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
|||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
li.LowPart = fad.nFileSizeLow;
|
li.LowPart = fad.nFileSizeLow;
|
||||||
@@ -252,12 +252,12 @@ void FileImpl::setSizeImpl(FileSizeImpl size)
|
|||||||
li.QuadPart = size;
|
li.QuadPart = size;
|
||||||
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
if (SetEndOfFile(fh.get()) == 0)
|
if (SetEndOfFile(fh.get()) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileImpl::setWriteableImpl(bool flag)
|
void FileImpl::setWriteableImpl(bool flag)
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
@@ -285,12 +285,8 @@ void FileImpl::copyToImpl(const std::string& path) const
|
|||||||
|
|
||||||
std::wstring upath;
|
std::wstring upath;
|
||||||
UnicodeConverter::toUTF16(path, upath);
|
UnicodeConverter::toUTF16(path, upath);
|
||||||
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) != 0)
|
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) == 0)
|
||||||
{
|
handleLastErrorImpl(_path);
|
||||||
FileImpl copy(path);
|
|
||||||
copy.setWriteableImpl(true);
|
|
||||||
}
|
|
||||||
else handleLastErrorImpl(_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -300,7 +296,7 @@ void FileImpl::renameToImpl(const std::string& path)
|
|||||||
|
|
||||||
std::wstring upath;
|
std::wstring upath;
|
||||||
UnicodeConverter::toUTF16(path, 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);
|
handleLastErrorImpl(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +307,7 @@ void FileImpl::removeImpl()
|
|||||||
|
|
||||||
if (isDirectoryImpl())
|
if (isDirectoryImpl())
|
||||||
{
|
{
|
||||||
if (RemoveDirectoryW(_upath.c_str()) == 0)
|
if (RemoveDirectoryW(_upath.c_str()) == 0)
|
||||||
handleLastErrorImpl(_path);
|
handleLastErrorImpl(_path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -343,7 +339,7 @@ bool FileImpl::createFileImpl()
|
|||||||
bool FileImpl::createDirectoryImpl()
|
bool FileImpl::createDirectoryImpl()
|
||||||
{
|
{
|
||||||
poco_assert (!_path.empty());
|
poco_assert (!_path.empty());
|
||||||
|
|
||||||
if (existsImpl() && isDirectoryImpl())
|
if (existsImpl() && isDirectoryImpl())
|
||||||
return false;
|
return false;
|
||||||
if (CreateDirectoryW(_upath.c_str(), 0) == 0)
|
if (CreateDirectoryW(_upath.c_str(), 0) == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user