added Poco::File::linkTo()

This commit is contained in:
Günter Obiltschnig
2017-12-14 10:35:07 +01:00
parent 9472b163b4
commit d29972ef24
12 changed files with 129 additions and 26 deletions

View File

@@ -163,10 +163,16 @@ bool FileImpl::isDirectoryImpl() const
bool FileImpl::isLinkImpl() const
{
return false;
poco_assert (!_path.empty());
DWORD attr = GetFileAttributes(_upath.c_str());
if (attr == INVALID_FILE_ATTRIBUTES)
handleLastErrorImpl(_path);
return (attr & FILE_ATTRIBUTE_DIRECTORY) == 0 && (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
}
bool FileImpl::isDeviceImpl() const
{
return
@@ -300,6 +306,23 @@ void FileImpl::renameToImpl(const std::string& path)
}
void FileImpl::linkToImpl(const std::string& path, int type) const
{
poco_assert (!_path.empty());
if (type == 0)
{
if (CreateHardLinkA(path.c_str(), _path.c_str(), NULL) == 0)
handleLastErrorImpl(_path);
}
else
{
if (CreateSymbolicLinkA(path.c_str(), _path.c_str(), (isDirectoryImpl() ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0) | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) == 0)
handleLastErrorImpl(_path);
}
}
void FileImpl::removeImpl()
{
poco_assert (!_path.empty());