Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mac monterey #1031

Merged
merged 2 commits into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/link/filelink.cpp
Expand Up @@ -38,14 +38,14 @@ void FileLink::writeData(const QByteArray& data)
}

// This save the data as a structure to deal with the timestamp
if (_openModeFlag == QIODevice::WriteOnly && _file.isWritable()) {
if (_openModeFlag == QIODevice::WriteOnly && isWritable()) {
QString time = QTime::fromMSecsSinceStartOfDay(_timer.elapsed()).toString(_timeFormat);
Pack pack {time, data};
_inout << pack.time << pack.data;
} else {
qCWarning(PING_PROTOCOL_FILELINK) << "Something is wrong!";
qCDebug(PING_PROTOCOL_FILELINK) << "File is opened as write only:" << (_openModeFlag == QIODevice::WriteOnly);
qCDebug(PING_PROTOCOL_FILELINK) << "File can be writable:" << _file.isWritable();
qCDebug(PING_PROTOCOL_FILELINK) << "File can be writable:" << isWritable();
}
}

Expand All @@ -67,10 +67,7 @@ bool FileLink::setConfiguration(const LinkConfiguration& linkConfiguration)
_file.setFileName(linkConfiguration.args()->at(0));

if (_openModeFlag == QIODevice::WriteOnly) {
// The file will be created when something is received
// Avoiding empty files
// Check if path is writable
return QFileInfo(QFileInfo(_file).canonicalPath()).isWritable();
return isWritable();
}

// Everything after this point is to deal with reading data
Expand Down Expand Up @@ -99,10 +96,8 @@ bool FileLink::setConfiguration(const LinkConfiguration& linkConfiguration)

bool FileLink::startConnection()
{
// The file will be created when something is received
// Avoiding empty files
if (_openModeFlag == QIODevice::WriteOnly) {
return QFileInfo(QFileInfo(_file).canonicalPath()).isWritable();
return isWritable();
}

if (!isOpen()) {
Expand Down Expand Up @@ -184,10 +179,22 @@ bool FileLink::isOpen()
{
// If filelink exist to create a log, the file will be only created after receiving the first data
// To return at least a good answer, we do check the path to see if it's writable
return (QFileInfo(QFileInfo(_file).canonicalPath()).isWritable() && _openModeFlag == QIODevice::WriteOnly)
return (isWritable() && _openModeFlag == QIODevice::WriteOnly)
|| _file.isReadable(); // If file is readable it's already opened and working
};

bool FileLink::isWritable()
{
// We should use the absoluteBasePath to make sure that the path is writable
// Using the complete path with the file name may result in problems (E.g: Mac)
Williangalvani marked this conversation as resolved.
Show resolved Hide resolved
// If the file does not exist yet the check may result in isWritable as false
// Checking for the base path is a working and equivalent check
// This also avoids the creation of empty files
const auto absoluteBasePath = QFileInfo(_file).absolutePath();
const bool isWritable = QFileInfo(absoluteBasePath).isWritable();
return isWritable;
}

bool FileLink::finishConnection()
{
// Stop reading log process if it's running
Expand Down
2 changes: 1 addition & 1 deletion src/link/filelink.h
Expand Up @@ -70,7 +70,7 @@ class FileLink : public AbstractLink {
* @return true
* @return false
*/
bool isWritable() final { return false; };
bool isWritable() final;

/**
* @brief Return package index
Expand Down