| 120 | } |
| 121 | |
| 122 | QString ChatFileManager::copyToIntermediateStorage(const QString &filePath) |
| 123 | { |
| 124 | QFileInfo fileInfo(filePath); |
| 125 | if (!fileInfo.exists() || !fileInfo.isFile()) { |
| 126 | LOG_MESSAGE(QString("Source file does not exist or is not a file: %1").arg(filePath)); |
| 127 | return QString(); |
| 128 | } |
| 129 | |
| 130 | if (fileInfo.size() == 0) { |
| 131 | LOG_MESSAGE(QString("Source file is empty: %1").arg(filePath)); |
| 132 | } |
| 133 | |
| 134 | const QString newFileName = generateIntermediateFileName(filePath); |
| 135 | const QString destinationPath = QDir(m_intermediateStorageDir).filePath(newFileName); |
| 136 | |
| 137 | if (QFileInfo::exists(destinationPath)) { |
| 138 | QFile::remove(destinationPath); |
| 139 | } |
| 140 | |
| 141 | if (!QFile::copy(filePath, destinationPath)) { |
| 142 | LOG_MESSAGE(QString("Failed to copy file: %1 -> %2").arg(filePath, destinationPath)); |
| 143 | return QString(); |
| 144 | } |
| 145 | |
| 146 | QFile copiedFile(destinationPath); |
| 147 | if (!copiedFile.exists()) { |
| 148 | LOG_MESSAGE(QString("Copied file does not exist after copy: %1").arg(destinationPath)); |
| 149 | return QString(); |
| 150 | } |
| 151 | |
| 152 | copiedFile.setPermissions(QFile::ReadUser | QFile::WriteUser); |
| 153 | |
| 154 | return destinationPath; |
| 155 | } |
| 156 | |
| 157 | QString ChatFileManager::getIntermediateStorageDir() |
| 158 | { |