@@ -490,7 +490,8 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
490
490
491
491
// For virtual files just dehydrate or create the file and be done
492
492
if (_item->_type == ItemTypeVirtualFileDehydration) {
493
- QString fsPath = propagator ()->fullLocalPath (_item->_file );
493
+ const auto fsPath = propagator ()->fullLocalPath (_item->_file );
494
+ makeParentFolderModifiable (fsPath);
494
495
if (!FileSystem::verifyFileUnchanged (fsPath, _item->_previousSize , _item->_previousModtime )) {
495
496
propagator ()->_anotherSyncNeeded = true ;
496
497
done (SyncFileItem::SoftError, tr (" File has changed since discovery" ), ErrorCategory::GenericError);
@@ -499,6 +500,7 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
499
500
500
501
qCDebug (lcPropagateDownload) << " dehydrating file" << _item->_file ;
501
502
if (FileSystem::isLnkFile (fsPath)) {
503
+ makeParentFolderModifiable (_tmpFile.fileName ());
502
504
const auto convertResult = vfs->convertToPlaceholder (fsPath, *_item);
503
505
if (!convertResult) {
504
506
qCCritical (lcPropagateDownload ()) << " error when converting a shortcut file to placeholder" << convertResult.error ();
@@ -532,6 +534,10 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
532
534
}
533
535
if (_item->_type == ItemTypeVirtualFile && !propagator ()->localFileNameClash (_item->_file )) {
534
536
qCDebug (lcPropagateDownload) << " creating virtual file" << _item->_file ;
537
+
538
+ const auto fsPath = propagator ()->fullLocalPath (_item->_file );
539
+ makeParentFolderModifiable (fsPath);
540
+
535
541
// do a klaas' case clash check.
536
542
if (propagator ()->localFileNameClash (_item->_file )) {
537
543
done (SyncFileItem::FileNameClash, tr (" File %1 can not be downloaded because of a local file name clash!" ).arg (QDir::toNativeSeparators (_item->_file )), ErrorCategory::GenericError);
@@ -666,6 +672,7 @@ void PropagateDownloadFile::startDownload()
666
672
tmpFileName = createDownloadTmpFileName (_item->_file );
667
673
}
668
674
_tmpFile.setFileName (propagator ()->fullLocalPath (tmpFileName));
675
+ makeParentFolderModifiable (_tmpFile.fileName ());
669
676
670
677
_resumeStart = _tmpFile.size ();
671
678
if (_resumeStart > 0 && _resumeStart == _item->_size ) {
@@ -680,32 +687,6 @@ void PropagateDownloadFile::startDownload()
680
687
FileSystem::setFileReadOnly (_tmpFile.fileName (), false );
681
688
}
682
689
683
- #if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
684
- try {
685
- const auto newDirPath = std::filesystem::path{_tmpFile.fileName ().toStdWString ()};
686
- Q_ASSERT (newDirPath.has_parent_path ());
687
- _parentPath = newDirPath.parent_path ();
688
- }
689
- catch (const std::filesystem::filesystem_error &e)
690
- {
691
- qCWarning (lcPropagateDownload) << " exception when checking parent folder access rights" << e.what () << e.path1 ().c_str () << e.path2 ().c_str ();
692
- }
693
- catch (const std::system_error &e)
694
- {
695
- qCWarning (lcPropagateDownload) << " exception when checking parent folder access rights" << e.what ();
696
- }
697
- catch (...)
698
- {
699
- qCWarning (lcPropagateDownload) << " exception when checking parent folder access rights" ;
700
- }
701
-
702
- if (FileSystem::isFolderReadOnly (_parentPath)) {
703
- FileSystem::setFolderPermissions (QString::fromStdWString (_parentPath.wstring ()), FileSystem::FolderPermissions::ReadWrite);
704
- emit propagator ()->touchedFile (QString::fromStdWString (_parentPath.wstring ()));
705
- _needParentFolderRestorePermissions = true ;
706
- }
707
- #endif
708
-
709
690
if (!_tmpFile.open (QIODevice::Append | QIODevice::Unbuffered)) {
710
691
qCWarning (lcPropagateDownload) << " could not open temporary file" << _tmpFile.fileName ();
711
692
done (SyncFileItem::NormalError, _tmpFile.errorString (), ErrorCategory::GenericError);
@@ -786,6 +767,47 @@ void PropagateDownloadFile::setDeleteExistingFolder(bool enabled)
786
767
_deleteExisting = enabled;
787
768
}
788
769
770
+ void PropagateDownloadFile::done (const SyncFileItem::Status status, const QString &errorString, const ErrorCategory category)
771
+ {
772
+ #if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
773
+ if (_needParentFolderRestorePermissions) {
774
+ FileSystem::setFolderPermissions (QString::fromStdWString (_parentPath.wstring ()), FileSystem::FolderPermissions::ReadOnly);
775
+ emit propagator ()->touchedFile (QString::fromStdWString (_parentPath.wstring ()));
776
+ _needParentFolderRestorePermissions = false ;
777
+ }
778
+ #endif
779
+ PropagateItemJob::done (status, errorString, category);
780
+ }
781
+
782
+ void PropagateDownloadFile::makeParentFolderModifiable (const QString &fileName)
783
+ {
784
+ #if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
785
+ try {
786
+ const auto newDirPath = std::filesystem::path{fileName.toStdWString ()};
787
+ Q_ASSERT (newDirPath.has_parent_path ());
788
+ _parentPath = newDirPath.parent_path ();
789
+ }
790
+ catch (const std::filesystem::filesystem_error &e)
791
+ {
792
+ qCWarning (lcPropagateDownload) << " exception when checking parent folder access rights" << e.what () << e.path1 ().c_str () << e.path2 ().c_str ();
793
+ }
794
+ catch (const std::system_error &e)
795
+ {
796
+ qCWarning (lcPropagateDownload) << " exception when checking parent folder access rights" << e.what ();
797
+ }
798
+ catch (...)
799
+ {
800
+ qCWarning (lcPropagateDownload) << " exception when checking parent folder access rights" ;
801
+ }
802
+
803
+ if (FileSystem::isFolderReadOnly (_parentPath)) {
804
+ FileSystem::setFolderPermissions (QString::fromStdWString (_parentPath.wstring ()), FileSystem::FolderPermissions::ReadWrite);
805
+ emit propagator ()->touchedFile (QString::fromStdWString (_parentPath.wstring ()));
806
+ _needParentFolderRestorePermissions = true ;
807
+ }
808
+ #endif
809
+ }
810
+
789
811
const char owncloudCustomSoftErrorStringC[] = " owncloud-custom-soft-error-string" ;
790
812
void PropagateDownloadFile::slotGetFinished ()
791
813
{
@@ -1328,7 +1350,7 @@ void PropagateDownloadFile::downloadFinished()
1328
1350
1329
1351
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
1330
1352
if (_needParentFolderRestorePermissions) {
1331
- FileSystem::setFolderPermissions (QString::fromStdWString (_parentPath.wstring ()), FileSystem::FolderPermissions::ReadWrite );
1353
+ FileSystem::setFolderPermissions (QString::fromStdWString (_parentPath.wstring ()), FileSystem::FolderPermissions::ReadOnly );
1332
1354
emit propagator ()->touchedFile (QString::fromStdWString (_parentPath.wstring ()));
1333
1355
_needParentFolderRestorePermissions = false ;
1334
1356
}
0 commit comments