Skip to content

Commit

Permalink
SyncFileItem: use accessor methods for _file member (#12031)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjv authored Jan 14, 2025
1 parent fa9b730 commit 5d882ca
Show file tree
Hide file tree
Showing 30 changed files with 270 additions and 286 deletions.
7 changes: 3 additions & 4 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,19 +470,18 @@ void Folder::showSyncResultPopup()
LogStatus status(LogStatusRename);
// if the path changes it's rather a move
QDir renTarget = QFileInfo(_syncResult.firstItemRenamed()->_renameTarget).dir();
QDir renSource = QFileInfo(_syncResult.firstItemRenamed()->_file).dir();
QDir renSource = QFileInfo(_syncResult.firstItemRenamed()->localName()).dir();
if (renTarget != renSource) {
status = LogStatusMove;
}
createGuiLog(_syncResult.firstItemRenamed()->_file, status,
_syncResult.numRenamedItems(), _syncResult.firstItemRenamed()->_renameTarget);
createGuiLog(_syncResult.firstItemRenamed()->localName(), status, _syncResult.numRenamedItems(), _syncResult.firstItemRenamed()->_renameTarget);
}

if (_syncResult.firstNewConflictItem()) {
createGuiLog(_syncResult.firstNewConflictItem()->destination(), LogStatusConflict, _syncResult.numNewConflictItems());
}
if (int errorCount = _syncResult.numErrorItems()) {
createGuiLog(_syncResult.firstItemError()->_file, LogStatusError, errorCount);
createGuiLog(_syncResult.firstItemError()->localName(), LogStatusError, errorCount);
}

qCInfo(lcFolder) << "Folder" << path() << "sync result: " << _syncResult.status();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ namespace {
} else {
estimatedUpBw += progress.fileProgress(citm._item).estimatedBandwidth;
}
allFilenames.append(QApplication::translate("FolderStatus", "'%1'").arg(citm._item._file));
allFilenames.append(QApplication::translate("FolderStatus", "'%1'").arg(citm._item.localName()));
}
if (curItemProgress == -1) {
curItemProgress = curItem._size;
}

const QString itemFileName = curItem._file;
const QString itemFileName = curItem.localName();
const QString kindString = Progress::asActionString(curItem);

QString fileProgressString;
Expand Down
3 changes: 1 addition & 2 deletions src/gui/issueswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ IssuesWidget::IssuesWidget(QWidget *parent)
});

connect(ProgressDispatcher::instance(), &ProgressDispatcher::excluded, this, [this](Folder *f, const QString &file) {
auto item = SyncFileItemPtr::create();
auto item = SyncFileItemPtr::create(file);
item->_status = SyncFileItem::FilenameReserved;
item->_file = file;
item->_errorString = tr("The file %1 was ignored as its name is reserved by %2").arg(file, Theme::instance()->appNameGUI());
_model->addProtocolItem(ProtocolItem { f, item });
});
Expand Down
4 changes: 2 additions & 2 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ void ownCloudGui::slotUpdateProgress(Folder *folder, const ProgressInfo &progres
if (!progress._lastCompletedItem.isEmpty() && shouldShowInRecentsMenu(progress._lastCompletedItem)) {
QString kindStr = Progress::asResultString(progress._lastCompletedItem);
QString timeStr = QTime::currentTime().toString(QStringLiteral("hh:mm"));
QString actionText = tr("%1 (%2, %3)").arg(progress._lastCompletedItem._file, kindStr, timeStr);
QString actionText = tr("%1 (%2, %3)").arg(progress._lastCompletedItem.localName(), kindStr, timeStr);
QAction *action = new QAction(actionText, this);
QString fullPath = folder->path() + QLatin1Char('/') + progress._lastCompletedItem._file;
QString fullPath = folder->path() + QLatin1Char('/') + progress._lastCompletedItem.localName();
if (QFile(fullPath).exists()) {
connect(action, &QAction::triggered, this, [this, fullPath] { this->slotOpenPath(fullPath); });
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void SyncRunFileLog::logItem(const SyncFileItem &item)
{
QDebug(&tmp).noquote() << dateTimeStr(Utility::parseRFC1123Date(QString::fromUtf8(item._responseTimeStamp))) << L
<< ((item.instruction() != CSYNC_INSTRUCTION_RENAME) ? item.destination()
: item._file + QStringLiteral(" -> ") + item._renameTarget)
: item.localName() + QStringLiteral(" -> ") + item._renameTarget)
<< L << item.instruction() << L << item._direction << L << L << item._modtime << L << item._etag << L << item._size << L
<< item._fileId << L << item._status << L << item._errorString << L << item._httpErrorCode << L << item._previousSize << L
<< item._previousModtime << L << item._requestId << L << Qt::endl;
Expand Down
68 changes: 34 additions & 34 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void ProcessDirectoryJob::process()
path._local = PathTuple::pathAppend(_currentFolder._local, e.localEntry.name);
} else if (e.dbEntry.isVirtualFile()) {
// We don't have a local entry - but it should be at this path
addVirtualFileSuffix(path._local);
path._local = addVirtualFileSuffix(path._local);
}
}

Expand Down Expand Up @@ -226,8 +226,7 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const QString &loc
return true;
}

auto item = SyncFileItemPtr::create();
item->_file = path;
auto item = SyncFileItemPtr::create(path);
item->_originalFile = path;
item->setInstruction(CSYNC_INSTRUCTION_IGNORE);

Expand All @@ -246,7 +245,7 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const QString &loc
item->_status = SyncFileItem::Excluded;
break;
case CSYNC_FILE_EXCLUDE_INVALID_CHAR:
if (item->_file.endsWith(QLatin1Char('.'))) {
if (item->localName().endsWith(QLatin1Char('.'))) {
item->_errorString = tr("File names ending with a period are not supported on this file system.");
} else {
const auto unsupportedCharacter = [](const QString &fName) {
Expand All @@ -257,7 +256,7 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const QString &loc
}
}
return QChar();
}(item->_file);
}(item->localName());

if (!unsupportedCharacter.isNull()) {
item->_errorString = tr("File names containing the character '%1' are not supported on this file system.")
Expand Down Expand Up @@ -336,7 +335,7 @@ void ProcessDirectoryJob::processFile(const PathTuple &path,
}

auto item = SyncFileItem::fromSyncJournalFileRecord(dbEntry);
item->_file = path._target;
item->setLocalName(path._target);
item->_originalFile = path._original;
item->_previousSize = dbEntry._fileSize;
item->_previousModtime = dbEntry._modtime;
Expand Down Expand Up @@ -494,7 +493,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
&& _pinState != PinState::AlwaysLocal) {
item->_type = ItemTypeVirtualFile;
if (isVfsWithSuffix()) {
addVirtualFileSuffix(path._original);
path._original = addVirtualFileSuffix(path._original);
}
}
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
Expand Down Expand Up @@ -593,11 +592,11 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
item->setInstruction(CSYNC_INSTRUCTION_RENAME);
item->_direction = SyncFileItem::Down;
item->_renameTarget = path._target;
item->_file = adjustedOriginalPath;
item->setLocalName(adjustedOriginalPath);
item->_originalFile = originalPath;
path._original = originalPath;
path._local = adjustedOriginalPath;
qCInfo(lcDisco) << "Rename detected (down) " << item->_file << " -> " << item->_renameTarget;
qCInfo(lcDisco) << "Rename detected (down) " << item->localName() << " -> " << item->_renameTarget;
};

if (wasDeletedOnServer) {
Expand Down Expand Up @@ -747,14 +746,14 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
// might have been renamed to that. Make sure that the base file is not
// deleted from the server.
if (dbEntry._modtime == localEntry.modtime && dbEntry._fileSize == localEntry.size) {
qCInfo(lcDisco) << "Base file was renamed to virtual file:" << item->_file;
qCInfo(lcDisco) << "Base file was renamed to virtual file:" << item->localName();
item->_direction = SyncFileItem::Down;
item->setInstruction(CSYNC_INSTRUCTION_SYNC);
item->_type = ItemTypeVirtualFileDehydration;
addVirtualFileSuffix(item->_file);
item->_renameTarget = item->_file;
item->setLocalName(addVirtualFileSuffix(item->localName()));
item->_renameTarget = item->localName();
} else {
qCInfo(lcDisco) << "Virtual file with non-virtual db entry, ignoring:" << item->_file;
qCInfo(lcDisco) << "Virtual file with non-virtual db entry, ignoring:" << item->localName();
item->setInstruction(CSYNC_INSTRUCTION_IGNORE);
}
}
Expand Down Expand Up @@ -981,7 +980,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
// TODO: move to SyncFileItem so its easier to refactor if item changes in any way...
item->_renameTarget = path._target;
path._server = adjustedOriginalPath;
item->_file = path._server;
item->setLocalName(path._server);
path._original = originalPath;
item->_originalFile = path._original;
item->_modtime = base._modtime;
Expand All @@ -1002,7 +1001,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
item->_type = ItemTypeFile;
}

qCInfo(lcDisco) << "Rename detected (up) " << item->_file << " -> " << item->_renameTarget;
qCInfo(lcDisco) << "Rename detected (up) " << item->localName() << " -> " << item->_renameTarget;
return path;
};
if (wasDeletedOnClient.first) {
Expand Down Expand Up @@ -1089,7 +1088,7 @@ void ProcessDirectoryJob::processFileConflict(const SyncFileItemPtr &item, const

if (item->instruction() == CSYNC_INSTRUCTION_UPDATE_METADATA) {
// Update the etag and other server metadata in the journal already
Q_ASSERT(item->_file == path._original);
Q_ASSERT(item->localName() == path._original);
Q_ASSERT(item->_size == serverEntry.size);
Q_ASSERT(item->_modtime == serverEntry.modtime);
Q_ASSERT(!serverEntry.etag.isEmpty());
Expand All @@ -1113,15 +1112,16 @@ void ProcessDirectoryJob::processFileFinalize(
// Adjust target path for virtual-suffix files
if (isVfsWithSuffix()) {
if (item->_type == ItemTypeVirtualFile) {
addVirtualFileSuffix(path._target);
if (item->instruction() == CSYNC_INSTRUCTION_RENAME)
addVirtualFileSuffix(item->_renameTarget);
else
addVirtualFileSuffix(item->_file);
path._target = addVirtualFileSuffix(path._target);
if (item->instruction() == CSYNC_INSTRUCTION_RENAME) {
item->_renameTarget = addVirtualFileSuffix(item->_renameTarget);
} else {
item->setLocalName(addVirtualFileSuffix(item->localName()));
}
} else if (item->_type == ItemTypeVirtualFileDehydration && item->instruction() == CSYNC_INSTRUCTION_SYNC) {
if (item->_renameTarget.isEmpty()) {
item->_renameTarget = item->_file;
addVirtualFileSuffix(item->_renameTarget);
item->_renameTarget = item->localName();
item->_renameTarget = addVirtualFileSuffix(item->_renameTarget);
}
}
}
Expand All @@ -1135,7 +1135,7 @@ void ProcessDirectoryJob::processFileFinalize(
item->_direction = _dirItem->_direction;
}

qCInfo(lcDisco) << "Discovered" << item->_file << item->instruction() << item->_direction << item->_type;
qCInfo(lcDisco) << "Discovered" << item->localName() << item->instruction() << item->_direction << item->_type;

if (item->isDirectory() && item->instruction() == CSYNC_INSTRUCTION_SYNC)
item->setInstruction(CSYNC_INSTRUCTION_UPDATE_METADATA);
Expand Down Expand Up @@ -1172,7 +1172,7 @@ void ProcessDirectoryJob::processBlacklisted(const PathTuple &path, const OCC::L
return;

auto item = SyncFileItem::fromSyncJournalFileRecord(dbEntry);
item->_file = path._target;
item->setLocalName(path._target);
item->_originalFile = path._original;
item->_inode = localEntry.inode;
item->_isSelectiveSync = true;
Expand All @@ -1186,7 +1186,7 @@ void ProcessDirectoryJob::processBlacklisted(const PathTuple &path, const OCC::L
_childIgnored = true;
}

qCInfo(lcDisco) << "Discovered (blacklisted) " << item->_file << item->instruction() << item->_direction << item->isDirectory();
qCInfo(lcDisco) << "Discovered (blacklisted) " << item->localName() << item->instruction() << item->_direction << item->isDirectory();

if (item->isDirectory() && item->instruction() != CSYNC_INSTRUCTION_IGNORE) {
auto job = new ProcessDirectoryJob(path, item, NormalQuery, InBlackList, this);
Expand All @@ -1213,12 +1213,12 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
// No permissions set
return true;
} else if (item->isDirectory() && !perms.hasPermission(RemotePermissions::CanAddSubDirectories)) {
qCWarning(lcDisco) << "checkForPermission: ERROR" << item->_file;
qCWarning(lcDisco) << "checkForPermission: ERROR" << item->localName();
item->setInstruction(CSYNC_INSTRUCTION_ERROR);
item->_errorString = tr("Not allowed because you don't have permission to add subfolders to that folder");
return false;
} else if (!item->isDirectory() && !perms.hasPermission(RemotePermissions::CanAddFile)) {
qCWarning(lcDisco) << "checkForPermission: ERROR" << item->_file;
qCWarning(lcDisco) << "checkForPermission: ERROR" << item->localName();
item->setInstruction(CSYNC_INSTRUCTION_ERROR);
item->_errorString = tr("Not allowed because you don't have permission to add files in that folder");
return false;
Expand All @@ -1236,7 +1236,7 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
item->_errorString = tr("Not allowed to upload this file because it is read-only on the server, restoring");
item->_direction = SyncFileItem::Down;
item->_isRestoration = true;
qCWarning(lcDisco) << "checkForPermission: RESTORING" << item->_file << item->_errorString;
qCWarning(lcDisco) << "checkForPermission: RESTORING" << item->localName() << item->_errorString;
// Take the things to write to the db from the "other" node (i.e: info from server).
// Do a lookup into the csync remote tree to get the metadata we need to restore.
qSwap(item->_size, item->_previousSize);
Expand All @@ -1246,7 +1246,7 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
break;
}
case CSYNC_INSTRUCTION_REMOVE: {
QString fileSlash = item->_file + QLatin1Char('/');
QString fileSlash = item->localName() + QLatin1Char('/');
auto forbiddenIt = _discoveryData->_forbiddenDeletes.upper_bound(fileSlash);
if (forbiddenIt != _discoveryData->_forbiddenDeletes.cbegin()) {
forbiddenIt--;
Expand All @@ -1257,7 +1257,7 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
item->_direction = SyncFileItem::Down;
item->_isRestoration = true;
item->_errorString = tr("Moved to invalid target, restoring");
qCWarning(lcDisco) << "checkForPermission: RESTORING" << item->_file << item->_errorString;
qCWarning(lcDisco) << "checkForPermission: RESTORING" << item->localName() << item->_errorString;
return true; // restore sub items
}
const auto perms = item->_remotePerm;
Expand All @@ -1270,7 +1270,7 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
item->_direction = SyncFileItem::Down;
item->_isRestoration = true;
item->_errorString = tr("Not allowed to remove, restoring");
qCWarning(lcDisco) << "checkForPermission: RESTORING" << item->_file << item->_errorString;
qCWarning(lcDisco) << "checkForPermission: RESTORING" << item->localName() << item->_errorString;
return true; // (we need to recurse to restore sub items)
}
break;
Expand Down Expand Up @@ -1382,9 +1382,9 @@ void ProcessDirectoryJob::dbError()
Q_EMIT _discoveryData->fatalError(tr("Error while reading the database"));
}

void ProcessDirectoryJob::addVirtualFileSuffix(QString &str) const
QString ProcessDirectoryJob::addVirtualFileSuffix(const QString &str) const
{
str.append(_discoveryData->_syncOptions._vfs->fileSuffix());
return QString(str).append(_discoveryData->_syncOptions._vfs->fileSuffix());
}

bool ProcessDirectoryJob::hasVirtualFileSuffix(const QString &str) const
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class ProcessDirectoryJob : public QObject
/** An DB operation failed */
void dbError();

void addVirtualFileSuffix(QString &str) const;
[[nodiscard]] QString addVirtualFileSuffix(const QString &str) const;
bool hasVirtualFileSuffix(const QString &str) const;
Q_REQUIRED_RESULT QString chopVirtualFileSuffix(const QString &str) const;

Expand Down
8 changes: 4 additions & 4 deletions src/libsync/localdiscoverytracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void LocalDiscoveryTracker::slotItemCompleted(const SyncFileItemPtr &item)
case SyncFileItem::Conflict:
Q_FALLTHROUGH();
case OCC::SyncFileItem::Message:
if (_previousLocalDiscoveryPaths.erase(item->_file)) {
qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->_file;
if (_previousLocalDiscoveryPaths.erase(item->localName())) {
qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->localName();
}
if (!item->_renameTarget.isEmpty() && _previousLocalDiscoveryPaths.erase(item->_renameTarget)) {
qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->_renameTarget;
Expand All @@ -106,8 +106,8 @@ void LocalDiscoveryTracker::slotItemCompleted(const SyncFileItemPtr &item)
Q_UNREACHABLE();
}

_localDiscoveryPaths.insert(item->_file);
qCDebug(lcLocalDiscoveryTracker) << "inserted error item" << item->_file;
_localDiscoveryPaths.insert(item->localName());
qCDebug(lcLocalDiscoveryTracker) << "inserted error item" << item->localName();
}

void LocalDiscoveryTracker::slotSyncFinished(bool success)
Expand Down
Loading

0 comments on commit 5d882ca

Please sign in to comment.