Beispiel #1
0
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 _WIN32_WINNT >= 0x0600 && defined(SYMBOLIC_LINK_FLAG_DIRECTORY)
		DWORD flags = 0;
		if (isDirectoryImpl()) flags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
#ifdef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
		flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
#endif
		if (CreateSymbolicLinkA(path.c_str(), _path.c_str(), flags) == 0)
			handleLastErrorImpl(_path);
#else
		throw Poco::NotImplementedException("Symbolic link support not available in used version of the Windows SDK")
#endif

	}
}
Beispiel #2
0
void FileImpl::setSizeImpl(FileSizeImpl size)
{
	poco_assert (!_path.empty());

	FileHandle fh(_path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
	LARGE_INTEGER li;
	li.QuadPart = size;
	if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == -1)
		handleLastErrorImpl(_path);
	if (SetEndOfFile(fh.get()) == 0) 
		handleLastErrorImpl(_path);
}
Beispiel #3
0
void FileImpl::setWriteableImpl(bool flag)
{
	poco_assert (!_path.empty());

	DWORD attr = GetFileAttributes(_path.c_str());
	if (attr == -1)
		handleLastErrorImpl(_path);
	if (flag)
		attr &= ~FILE_ATTRIBUTE_READONLY;
	else
		attr |= FILE_ATTRIBUTE_READONLY;
	if (SetFileAttributes(_path.c_str(), attr) == 0)
		handleLastErrorImpl(_path);
}
Beispiel #4
0
void FileImpl::removeImpl()
{
	poco_assert (!_path.empty());

	if (isDirectoryImpl())
	{
		if (RemoveDirectoryA(_path.c_str()) == 0) 
			handleLastErrorImpl(_path);
	}
	else
	{
		if (DeleteFileA(_path.c_str()) == 0)
			handleLastErrorImpl(_path);
	}
}
Beispiel #5
0
void FileImpl::copyToImpl(const std::string& path) const
{
	poco_assert (!_path.empty());

	if (CopyFileA(_path.c_str(), path.c_str(), FALSE) == 0)
		handleLastErrorImpl(_path);
}
Beispiel #6
0
void FileImpl::setSizeImpl(FileSizeImpl size)
{
	poco_assert (!_path.empty());

	if (truncate(_path.c_str(), size) != 0)
		handleLastErrorImpl(_path);
}
Beispiel #7
0
void FileImpl::renameToImpl(const std::string& path)
{
	poco_assert (!_path.empty());

	if (MoveFileA(_path.c_str(), path.c_str()) == 0) 
		handleLastErrorImpl(_path);
}
Beispiel #8
0
void FileImpl::renameToImpl(const std::string& path)
{
	poco_assert (!_path.empty());

	if (MoveFileExA(_path.c_str(), path.c_str(), MOVEFILE_REPLACE_EXISTING) == 0)
		handleLastErrorImpl(_path);
}
Beispiel #9
0
void FileImpl::renameToImpl(const std::string& path)
{
    poco_assert (!_path.empty());

    std::wstring upath;
    UnicodeConverter::toUTF16(path, upath);
    if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
        handleLastErrorImpl(_path);
}
Beispiel #10
0
bool FileImpl::canWriteImpl() const
{
	poco_assert (!_path.empty());
	
	DWORD attr = GetFileAttributes(_path.c_str());
	if (attr == 0xFFFFFFFF)
		handleLastErrorImpl(_path);
	return (attr & FILE_ATTRIBUTE_READONLY) == 0;
}
Beispiel #11
0
FileImpl::FileSizeImpl FileImpl::freeSpaceImpl() const
{
	poco_assert(!_path.empty());

	ULARGE_INTEGER space;
	if (!GetDiskFreeSpaceExW(_upath.c_str(), NULL, NULL, &space))
		handleLastErrorImpl(_path);
	return space.QuadPart;
}
Beispiel #12
0
void FileImpl::copyToImpl(const std::string& path) const
{
	poco_assert (!_path.empty());

	std::wstring upath;
	UnicodeConverter::toUTF16(path, upath);
	if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) == 0)
		handleLastErrorImpl(_path);
}
Beispiel #13
0
Timestamp FileImpl::getLastModifiedImpl() const
{
	poco_assert (!_path.empty());

	WIN32_FILE_ATTRIBUTE_DATA fad;
	if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0) 
		handleLastErrorImpl(_path);
	return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
}
Beispiel #14
0
bool FileImpl::isDirectoryImpl() const
{
	poco_assert (!_path.empty());

	DWORD attr = GetFileAttributes(_path.c_str());
	if (attr == 0xFFFFFFFF)
		handleLastErrorImpl(_path);
	return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
Beispiel #15
0
bool FileImpl::isLinkImpl() const
{
	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;
}
Beispiel #16
0
bool FileImpl::isHiddenImpl() const
{
	poco_assert (!_path.empty());

	DWORD attr = GetFileAttributes(_path.c_str());
	if (attr == 0xFFFFFFFF)
		handleLastErrorImpl(_path);
	return (attr & FILE_ATTRIBUTE_HIDDEN) != 0;
}
Beispiel #17
0
bool FileImpl::createDirectoryImpl()
{
	poco_assert (!_path.empty());

	if (existsImpl() && isDirectoryImpl())
		return false;
	if (mkdir(_path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) != 0) 
		handleLastErrorImpl(_path);
	return true;
}
Beispiel #18
0
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
{
    poco_assert (!_path.empty());

    struct utimbuf tb;
    tb.actime  = ts.epochTime();
    tb.modtime = ts.epochTime();
    if (utime(const_cast<char*>(_path.c_str()), &tb) != 0)
        handleLastErrorImpl(_path);
}
Beispiel #19
0
bool FileImpl::createDirectoryImpl()
{
	poco_assert (!_path.empty());
	
	if (existsImpl() && isDirectoryImpl())
		return false;
	if (CreateDirectoryA(_path.c_str(), 0) == 0)
		handleLastErrorImpl(_path);
	return true;
}
Beispiel #20
0
void FileImpl::copyToImpl(const std::string& path) const
{
    poco_assert (!_path.empty());

    int sd = open(_path.c_str(), O_RDONLY, 0);
    if (sd == -1) handleLastErrorImpl(_path);

    struct stat st;
    if (fstat(sd, &st) != 0)
    {
        close(sd);
        handleLastErrorImpl(_path);
    }
    const long blockSize = st.st_blksize;

    int dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode & S_IRWXU);
    if (dd == -1)
    {
        close(sd);
        handleLastErrorImpl(path);
    }
    Buffer<char> buffer(blockSize);
    try
    {
        int n;
        while ((n = read(sd, buffer.begin(), blockSize)) > 0)
        {
            if (write(dd, buffer.begin(), n) != n)
                handleLastErrorImpl(path);
        }
        if (n < 0)
            handleLastErrorImpl(_path);
    }
    catch (...)
    {
        close(sd);
        close(dd);
        throw;
    }
    close(sd);
    close(dd);
}
Beispiel #21
0
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
{
    poco_assert (!_path.empty());

    struct stat st;
    if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
        return st.st_size;
    else
        handleLastErrorImpl(_path);
    return 0;
}
Beispiel #22
0
Timestamp FileImpl::createdImpl() const
{
	poco_assert (!_path.empty());

	struct stat st;
	if (stat(_path.c_str(), &st) == 0)
		return Timestamp(st.st_mtime);
	else
		handleLastErrorImpl(_path);
	return 0;
}
Beispiel #23
0
bool FileImpl::isLinkImpl() const
{
	poco_assert (!_path.empty());

	struct stat st;
	if (lstat(_path.c_str(), &st) == 0)
		return S_ISLNK(st.st_mode);
	else
		handleLastErrorImpl(_path);
	return false;
}
Beispiel #24
0
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);
}
Beispiel #25
0
void FileImpl::setExecutableImpl(bool flag)
{
	poco_assert (!_path.empty());

	struct stat st;
	if (stat(_path.c_str(), &st) != 0) 
		handleLastErrorImpl(_path);
	mode_t mode;
	if (flag)
	{
		mode = st.st_mode | S_IXUSR;
	}
	else
	{
		mode_t wmask = S_IXUSR | S_IXGRP | S_IXOTH;
		mode = st.st_mode & ~wmask;
	}
	if (chmod(_path.c_str(), mode) != 0) 
		handleLastErrorImpl(_path);
}
Beispiel #26
0
bool FileImpl::isDeviceImpl() const
{
    poco_assert (!_path.empty());

    struct stat st;
    if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
        return S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode);
    else
        handleLastErrorImpl(_path);
    return false;
}
Beispiel #27
0
Timestamp FileImpl::getLastModifiedImpl() const
{
    poco_assert (!_path.empty());

    struct stat st;
    if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
        return Timestamp::fromEpochTime(st.st_mtime);
    else
        handleLastErrorImpl(_path);
    return 0;
}
Beispiel #28
0
void FileImpl::removeImpl()
{
    poco_assert (!_path.empty());

    int rc;
    if (!isLinkImpl() && isDirectoryImpl())
        rc = rmdir(_path.c_str());
    else
        rc = unlink(const_cast<char*>(_path.c_str()));
    if (rc) handleLastErrorImpl(_path);
}
Beispiel #29
0
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
{
	poco_assert (!_path.empty());

	WIN32_FILE_ATTRIBUTE_DATA fad;
	if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0) 
		handleLastErrorImpl(_path);
	LARGE_INTEGER li;
	li.LowPart  = fad.nFileSizeLow;
	li.HighPart = fad.nFileSizeHigh;
	return li.QuadPart;
}
Beispiel #30
0
bool FileImpl::isDeviceImpl() const
{
	poco_assert (!_path.empty());

	FileHandle fh(_path, GENERIC_READ, 0, OPEN_EXISTING);
	DWORD type = GetFileType(fh.get());
	if (type == FILE_TYPE_CHAR)
		return true;
	else if (type == FILE_TYPE_UNKNOWN && GetLastError() != NO_ERROR)
		handleLastErrorImpl(_path);
	return false;
}