Changeset View
Standalone View
src/core/copyjob.cpp
Show First 20 Lines • Show All 258 Lines • ▼ Show 20 Line(s) | 232 | // KIO::Job* linkNextFile( const QUrl& uSource, const QUrl& uDest, bool overwrite ); | |||
---|---|---|---|---|---|
259 | /** | 259 | /** | ||
260 | * Forward signal from subjob | 260 | * Forward signal from subjob | ||
261 | * @param size the total size | 261 | * @param size the total size | ||
262 | */ | 262 | */ | ||
263 | void slotTotalSize(KJob *, qulonglong size); | 263 | void slotTotalSize(KJob *, qulonglong size); | ||
264 | 264 | | |||
265 | void slotReport(); | 265 | void slotReport(); | ||
266 | 266 | | |||
267 | KIO::JobFlag privilegeExecFlag() const { return m_privilegeExecutionEnabled ? PrivilegeExecution : DefaultFlags; } | ||||
dfaure: mark the method as const | |||||
268 | | ||||
267 | Q_DECLARE_PUBLIC(CopyJob) | 269 | Q_DECLARE_PUBLIC(CopyJob) | ||
268 | 270 | | |||
269 | static inline CopyJob *newJob(const QList<QUrl> &src, const QUrl &dest, | 271 | static inline CopyJob *newJob(const QList<QUrl> &src, const QUrl &dest, | ||
270 | CopyJob::CopyMode mode, bool asMethod, JobFlags flags) | 272 | CopyJob::CopyMode mode, bool asMethod, JobFlags flags) | ||
271 | { | 273 | { | ||
272 | CopyJob *job = new CopyJob(*new CopyJobPrivate(src, dest, mode, asMethod)); | 274 | CopyJob *job = new CopyJob(*new CopyJobPrivate(src, dest, mode, asMethod)); | ||
273 | job->setUiDelegate(KIO::createDefaultJobUiDelegate()); | 275 | job->setUiDelegate(KIO::createDefaultJobUiDelegate()); | ||
274 | if (!(flags & HideProgressInfo)) { | 276 | if (!(flags & HideProgressInfo)) { | ||
275 | KIO::getJobTracker()->registerJob(job); | 277 | KIO::getJobTracker()->registerJob(job); | ||
276 | } | 278 | } | ||
277 | if (flags & KIO::Overwrite) { | 279 | if (flags & KIO::Overwrite) { | ||
278 | job->d_func()->m_bOverwriteAllDirs = true; | 280 | job->d_func()->m_bOverwriteAllDirs = true; | ||
279 | job->d_func()->m_bOverwriteAllFiles = true; | 281 | job->d_func()->m_bOverwriteAllFiles = true; | ||
280 | } | 282 | } | ||
283 | if (!(flags & KIO::NoPrivilegeExecution)) { | ||||
284 | job->d_func()->m_privilegeExecutionEnabled = true; | ||||
dfaure: switch() ? | |||||
285 | FileOperationType copyType; | ||||
286 | switch (mode) { | ||||
287 | case CopyJob::Copy: | ||||
288 | copyType = Copy; | ||||
289 | break; | ||||
290 | case CopyJob::Move: | ||||
291 | copyType = Move; | ||||
292 | break; | ||||
293 | case CopyJob::Link: | ||||
294 | copyType = Symlink; | ||||
295 | break; | ||||
296 | } | ||||
Remove default statement, which would leave the variable uninitialized. This way the compiler will warn if a new value is added to the CopyMode enum. dfaure: Remove default statement, which would leave the variable uninitialized. This way the compiler… | |||||
297 | job->d_func()->m_operationType = copyType; | ||||
298 | } | ||||
281 | return job; | 299 | return job; | ||
282 | } | 300 | } | ||
283 | }; | 301 | }; | ||
284 | 302 | | |||
285 | CopyJob::CopyJob(CopyJobPrivate &dd) | 303 | CopyJob::CopyJob(CopyJobPrivate &dd) | ||
286 | : Job(dd) | 304 | : Job(dd) | ||
287 | { | 305 | { | ||
288 | setProperty("destUrl", d_func()->m_dest.toString()); | 306 | setProperty("destUrl", d_func()->m_dest.toString()); | ||
▲ Show 20 Lines • Show All 629 Lines • ▼ Show 20 Line(s) | 912 | { | |||
918 | info.uSource = m_currentSrcURL; | 936 | info.uSource = m_currentSrcURL; | ||
919 | info.uDest = dest; | 937 | info.uDest = dest; | ||
920 | QList<CopyInfo> files; | 938 | QList<CopyInfo> files; | ||
921 | files.append(info); | 939 | files.append(info); | ||
922 | emit q->aboutToCreate(q, files); | 940 | emit q->aboutToCreate(q, files); | ||
923 | 941 | | |||
924 | KIO_ARGS << m_currentSrcURL << dest << (qint8) false /*no overwrite*/; | 942 | KIO_ARGS << m_currentSrcURL << dest << (qint8) false /*no overwrite*/; | ||
925 | SimpleJob *newJob = SimpleJobPrivate::newJobNoUi(slave_url, CMD_RENAME, packedArgs); | 943 | SimpleJob *newJob = SimpleJobPrivate::newJobNoUi(slave_url, CMD_RENAME, packedArgs); | ||
944 | newJob->setParentJob(q); | ||||
926 | Scheduler::setJobPriority(newJob, 1); | 945 | Scheduler::setJobPriority(newJob, 1); | ||
927 | q->addSubjob(newJob); | 946 | q->addSubjob(newJob); | ||
928 | if (m_currentSrcURL.adjusted(QUrl::RemoveFilename) != dest.adjusted(QUrl::RemoveFilename)) { // For the user, moving isn't renaming. Only renaming is. | 947 | if (m_currentSrcURL.adjusted(QUrl::RemoveFilename) != dest.adjusted(QUrl::RemoveFilename)) { // For the user, moving isn't renaming. Only renaming is. | ||
929 | m_bOnlyRenames = false; | 948 | m_bOnlyRenames = false; | ||
930 | } | 949 | } | ||
931 | } | 950 | } | ||
932 | 951 | | |||
933 | void CopyJobPrivate::startListing(const QUrl &src) | 952 | void CopyJobPrivate::startListing(const QUrl &src) | ||
▲ Show 20 Lines • Show All 288 Lines • ▼ Show 20 Line(s) | 1240 | } else { | |||
1222 | udir = (*it).uDest; | 1241 | udir = (*it).uDest; | ||
1223 | } | 1242 | } | ||
1224 | } | 1243 | } | ||
1225 | } | 1244 | } | ||
1226 | if (!udir.isEmpty()) { // any dir to create, finally ? | 1245 | if (!udir.isEmpty()) { // any dir to create, finally ? | ||
1227 | // Create the directory - with default permissions so that we can put files into it | 1246 | // Create the directory - with default permissions so that we can put files into it | ||
1228 | // TODO : change permissions once all is finished; but for stuff coming from CDROM it sucks... | 1247 | // TODO : change permissions once all is finished; but for stuff coming from CDROM it sucks... | ||
1229 | KIO::SimpleJob *newjob = KIO::mkdir(udir, -1); | 1248 | KIO::SimpleJob *newjob = KIO::mkdir(udir, -1); | ||
1249 | newjob->setParentJob(q); | ||||
1230 | Scheduler::setJobPriority(newjob, 1); | 1250 | Scheduler::setJobPriority(newjob, 1); | ||
1231 | if (shouldOverwriteFile(udir.path())) { // if we are overwriting an existing file or symlink | 1251 | if (shouldOverwriteFile(udir.path())) { // if we are overwriting an existing file or symlink | ||
1232 | newjob->addMetaData(QStringLiteral("overwrite"), QStringLiteral("true")); | 1252 | newjob->addMetaData(QStringLiteral("overwrite"), QStringLiteral("true")); | ||
1233 | } | 1253 | } | ||
1234 | 1254 | | |||
1235 | m_currentDestURL = udir; | 1255 | m_currentDestURL = udir; | ||
1236 | m_bURLDirty = true; | 1256 | m_bURLDirty = true; | ||
1237 | 1257 | | |||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 1342 | } else { // no error | |||
1323 | // Special case for moving links. That operation needs two jobs, unlike others. | 1343 | // Special case for moving links. That operation needs two jobs, unlike others. | ||
1324 | if (m_bCurrentOperationIsLink && m_mode == CopyJob::Move | 1344 | if (m_bCurrentOperationIsLink && m_mode == CopyJob::Move | ||
1325 | && !qobject_cast<KIO::DeleteJob *>(job) // Deleting source not already done | 1345 | && !qobject_cast<KIO::DeleteJob *>(job) // Deleting source not already done | ||
1326 | ) { | 1346 | ) { | ||
1327 | q->removeSubjob(job); | 1347 | q->removeSubjob(job); | ||
1328 | assert(!q->hasSubjobs()); | 1348 | assert(!q->hasSubjobs()); | ||
1329 | // The only problem with this trick is that the error handling for this del operation | 1349 | // The only problem with this trick is that the error handling for this del operation | ||
1330 | // is not going to be right... see 'Very special case' above. | 1350 | // is not going to be right... see 'Very special case' above. | ||
1331 | KIO::Job *newjob = KIO::del((*it).uSource, HideProgressInfo); | 1351 | KIO::Job *newjob = KIO::del((*it).uSource, HideProgressInfo | privilegeExecFlag()); | ||
1352 | newjob->setParentJob(q); | ||||
1332 | q->addSubjob(newjob); | 1353 | q->addSubjob(newjob); | ||
1333 | return; // Don't move to next file yet ! | 1354 | return; // Don't move to next file yet ! | ||
1334 | } | 1355 | } | ||
1335 | 1356 | | |||
1336 | const QUrl finalUrl = finalDestUrl((*it).uSource, (*it).uDest); | 1357 | const QUrl finalUrl = finalDestUrl((*it).uSource, (*it).uDest); | ||
1337 | 1358 | | |||
1338 | if (m_bCurrentOperationIsLink) { | 1359 | if (m_bCurrentOperationIsLink) { | ||
1339 | QString target = (m_mode == CopyJob::Link ? (*it).uSource.path() : (*it).linkDest); | 1360 | QString target = (m_mode == CopyJob::Link ? (*it).uSource.path() : (*it).linkDest); | ||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Line(s) | 1519 | { | |||
1499 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking"; | 1520 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking"; | ||
1500 | if ( | 1521 | if ( | ||
1501 | (uSource.scheme() == uDest.scheme()) && | 1522 | (uSource.scheme() == uDest.scheme()) && | ||
1502 | (uSource.host() == uDest.host()) && | 1523 | (uSource.host() == uDest.host()) && | ||
1503 | (uSource.port() == uDest.port()) && | 1524 | (uSource.port() == uDest.port()) && | ||
1504 | (uSource.userName() == uDest.userName()) && | 1525 | (uSource.userName() == uDest.userName()) && | ||
1505 | (uSource.password() == uDest.password())) { | 1526 | (uSource.password() == uDest.password())) { | ||
1506 | // This is the case of creating a real symlink | 1527 | // This is the case of creating a real symlink | ||
1507 | KIO::SimpleJob *newJob = KIO::symlink(uSource.path(), uDest, flags | HideProgressInfo /*no GUI*/); | 1528 | KIO::SimpleJob *newJob = KIO::symlink(uSource.path(), uDest, flags | HideProgressInfo /*no GUI*/ | privilegeExecFlag()); | ||
1529 | newJob->setParentJob(q_func()); | ||||
1508 | Scheduler::setJobPriority(newJob, 1); | 1530 | Scheduler::setJobPriority(newJob, 1); | ||
1509 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << uSource.path() << "link=" << uDest; | 1531 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << uSource.path() << "link=" << uDest; | ||
1510 | //emit linking( this, uSource.path(), uDest ); | 1532 | //emit linking( this, uSource.path(), uDest ); | ||
1511 | m_bCurrentOperationIsLink = true; | 1533 | m_bCurrentOperationIsLink = true; | ||
1512 | m_currentSrcURL = uSource; | 1534 | m_currentSrcURL = uSource; | ||
1513 | m_currentDestURL = uDest; | 1535 | m_currentDestURL = uDest; | ||
1514 | m_bURLDirty = true; | 1536 | m_bURLDirty = true; | ||
1515 | //Observer::self()->slotCopying( this, uSource, uDest ); // should be slotLinking perhaps | 1537 | //Observer::self()->slotCopying( this, uSource, uDest ); // should be slotLinking perhaps | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 1609 | if (bCopyFile) { // any file to create, finally ? | |||
1627 | } else if (!(*it).linkDest.isEmpty() && | 1649 | } else if (!(*it).linkDest.isEmpty() && | ||
1628 | (uSource.scheme() == uDest.scheme()) && | 1650 | (uSource.scheme() == uDest.scheme()) && | ||
1629 | (uSource.host() == uDest.host()) && | 1651 | (uSource.host() == uDest.host()) && | ||
1630 | (uSource.port() == uDest.port()) && | 1652 | (uSource.port() == uDest.port()) && | ||
1631 | (uSource.userName() == uDest.userName()) && | 1653 | (uSource.userName() == uDest.userName()) && | ||
1632 | (uSource.password() == uDest.password())) | 1654 | (uSource.password() == uDest.password())) | ||
1633 | // Copying a symlink - only on the same protocol/host/etc. (#5601, downloading an FTP file through its link), | 1655 | // Copying a symlink - only on the same protocol/host/etc. (#5601, downloading an FTP file through its link), | ||
1634 | { | 1656 | { | ||
1635 | KIO::SimpleJob *newJob = KIO::symlink((*it).linkDest, uDest, flags | HideProgressInfo /*no GUI*/); | 1657 | KIO::SimpleJob *newJob = KIO::symlink((*it).linkDest, uDest, flags | HideProgressInfo /*no GUI*/ | privilegeExecFlag()); | ||
1658 | newJob->setParentJob(q); | ||||
1636 | Scheduler::setJobPriority(newJob, 1); | 1659 | Scheduler::setJobPriority(newJob, 1); | ||
1637 | newjob = newJob; | 1660 | newjob = newJob; | ||
1638 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << (*it).linkDest << "link=" << uDest; | 1661 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << (*it).linkDest << "link=" << uDest; | ||
1639 | m_currentSrcURL = QUrl::fromUserInput((*it).linkDest); | 1662 | m_currentSrcURL = QUrl::fromUserInput((*it).linkDest); | ||
1640 | m_currentDestURL = uDest; | 1663 | m_currentDestURL = uDest; | ||
1641 | m_bURLDirty = true; | 1664 | m_bURLDirty = true; | ||
1642 | //emit linking( this, (*it).linkDest, uDest ); | 1665 | //emit linking( this, (*it).linkDest, uDest ); | ||
1643 | //Observer::self()->slotCopying( this, m_currentSrcURL, uDest ); // should be slotLinking perhaps | 1666 | //Observer::self()->slotCopying( this, m_currentSrcURL, uDest ); // should be slotLinking perhaps | ||
1644 | m_bCurrentOperationIsLink = true; | 1667 | m_bCurrentOperationIsLink = true; | ||
1645 | // NOTE: if we are moving stuff, the deletion of the source will be done in slotResultCopyingFiles | 1668 | // NOTE: if we are moving stuff, the deletion of the source will be done in slotResultCopyingFiles | ||
1646 | } else if (m_mode == CopyJob::Move) { // Moving a file | 1669 | } else if (m_mode == CopyJob::Move) { // Moving a file | ||
1647 | KIO::FileCopyJob *moveJob = KIO::file_move(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/); | 1670 | KIO::FileCopyJob *moveJob = KIO::file_move(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/ | privilegeExecFlag()); | ||
1671 | moveJob->setParentJob(q); | ||||
1648 | moveJob->setSourceSize((*it).size); | 1672 | moveJob->setSourceSize((*it).size); | ||
1649 | moveJob->setModificationTime((*it).mtime); // #55804 | 1673 | moveJob->setModificationTime((*it).mtime); // #55804 | ||
1650 | newjob = moveJob; | 1674 | newjob = moveJob; | ||
Should the flag always be set here? Or only if m_privilegeExecutionEnabled is true? dfaure: Should the flag always be set here? Or only if m_privilegeExecutionEnabled is true? | |||||
Ideally it should be set when m_privilegeExecutionEnabled is true. But it will add more lines. Even though its just 2-3 lines, it doesn't look good. chinmoyr: Ideally it should be set when m_privilegeExecutionEnabled is true. But it will add more lines. | |||||
To me it looks worse to unconditionally pass a security-critical flag when it shouldn't be set, it reads like a security hole (even if, as you say, upon further research it turns out that the flag has no effect). Maybe make it a helper method flagsForSubJob() to avoid any duplication. BTW isn't the flag missing for the KIO::symlink case above? dfaure: To me it looks worse to unconditionally pass a security-critical flag when it shouldn't be set… | |||||
1651 | qCDebug(KIO_COPYJOB_DEBUG) << "Moving" << uSource << "to" << uDest; | 1675 | qCDebug(KIO_COPYJOB_DEBUG) << "Moving" << uSource << "to" << uDest; | ||
1652 | //emit moving( this, uSource, uDest ); | 1676 | //emit moving( this, uSource, uDest ); | ||
1653 | m_currentSrcURL = uSource; | 1677 | m_currentSrcURL = uSource; | ||
1654 | m_currentDestURL = uDest; | 1678 | m_currentDestURL = uDest; | ||
1655 | m_bURLDirty = true; | 1679 | m_bURLDirty = true; | ||
1656 | //Observer::self()->slotMoving( this, uSource, uDest ); | 1680 | //Observer::self()->slotMoving( this, uSource, uDest ); | ||
1657 | } else { // Copying a file | 1681 | } else { // Copying a file | ||
1658 | KIO::FileCopyJob *copyJob = KIO::file_copy(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/); | 1682 | KIO::FileCopyJob *copyJob = KIO::file_copy(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/ | privilegeExecFlag()); | ||
1659 | copyJob->setParentJob(q); // in case of rename dialog | 1683 | copyJob->setParentJob(q); // in case of rename dialog | ||
1660 | copyJob->setSourceSize((*it).size); | 1684 | copyJob->setSourceSize((*it).size); | ||
1661 | copyJob->setModificationTime((*it).mtime); | 1685 | copyJob->setModificationTime((*it).mtime); | ||
1662 | newjob = copyJob; | 1686 | newjob = copyJob; | ||
1663 | qCDebug(KIO_COPYJOB_DEBUG) << "Copying" << uSource << "to" << uDest; | 1687 | qCDebug(KIO_COPYJOB_DEBUG) << "Copying" << uSource << "to" << uDest; | ||
1664 | m_currentSrcURL = uSource; | 1688 | m_currentSrcURL = uSource; | ||
1665 | m_currentDestURL = uDest; | 1689 | m_currentDestURL = uDest; | ||
1666 | m_bURLDirty = true; | 1690 | m_bURLDirty = true; | ||
Show All 14 Lines | |||||
1681 | { | 1705 | { | ||
1682 | Q_Q(CopyJob); | 1706 | Q_Q(CopyJob); | ||
1683 | if (m_mode == CopyJob::Move && !dirsToRemove.isEmpty()) { // some dirs to delete ? | 1707 | if (m_mode == CopyJob::Move && !dirsToRemove.isEmpty()) { // some dirs to delete ? | ||
1684 | state = STATE_DELETING_DIRS; | 1708 | state = STATE_DELETING_DIRS; | ||
1685 | m_bURLDirty = true; | 1709 | m_bURLDirty = true; | ||
1686 | // Take first dir to delete out of list - last ones first ! | 1710 | // Take first dir to delete out of list - last ones first ! | ||
1687 | QList<QUrl>::Iterator it = --dirsToRemove.end(); | 1711 | QList<QUrl>::Iterator it = --dirsToRemove.end(); | ||
1688 | SimpleJob *job = KIO::rmdir(*it); | 1712 | SimpleJob *job = KIO::rmdir(*it); | ||
1713 | job->setParentJob(q); | ||||
1689 | Scheduler::setJobPriority(job, 1); | 1714 | Scheduler::setJobPriority(job, 1); | ||
1690 | dirsToRemove.erase(it); | 1715 | dirsToRemove.erase(it); | ||
1691 | q->addSubjob(job); | 1716 | q->addSubjob(job); | ||
1692 | } else { | 1717 | } else { | ||
1693 | // This step is done, move on | 1718 | // This step is done, move on | ||
1694 | state = STATE_SETTING_DIR_ATTRIBUTES; | 1719 | state = STATE_SETTING_DIR_ATTRIBUTES; | ||
1695 | m_directoriesCopiedIterator = m_directoriesCopied.constBegin(); | 1720 | m_directoriesCopiedIterator = m_directoriesCopied.constBegin(); | ||
1696 | setNextDirAttribute(); | 1721 | setNextDirAttribute(); | ||
1697 | } | 1722 | } | ||
1698 | } | 1723 | } | ||
1699 | 1724 | | |||
1700 | void CopyJobPrivate::setNextDirAttribute() | 1725 | void CopyJobPrivate::setNextDirAttribute() | ||
1701 | { | 1726 | { | ||
1702 | Q_Q(CopyJob); | 1727 | Q_Q(CopyJob); | ||
1703 | while (m_directoriesCopiedIterator != m_directoriesCopied.constEnd() && | 1728 | while (m_directoriesCopiedIterator != m_directoriesCopied.constEnd() && | ||
1704 | !(*m_directoriesCopiedIterator).mtime.isValid()) { | 1729 | !(*m_directoriesCopiedIterator).mtime.isValid()) { | ||
1705 | ++m_directoriesCopiedIterator; | 1730 | ++m_directoriesCopiedIterator; | ||
1706 | } | 1731 | } | ||
1707 | if (m_directoriesCopiedIterator != m_directoriesCopied.constEnd()) { | 1732 | if (m_directoriesCopiedIterator != m_directoriesCopied.constEnd()) { | ||
1708 | const QUrl url = (*m_directoriesCopiedIterator).uDest; | 1733 | const QUrl url = (*m_directoriesCopiedIterator).uDest; | ||
1709 | const QDateTime dt = (*m_directoriesCopiedIterator).mtime; | 1734 | const QDateTime dt = (*m_directoriesCopiedIterator).mtime; | ||
1710 | ++m_directoriesCopiedIterator; | 1735 | ++m_directoriesCopiedIterator; | ||
1711 | 1736 | | |||
1712 | KIO::SimpleJob *job = KIO::setModificationTime(url, dt); | 1737 | KIO::SimpleJob *job = KIO::setModificationTime(url, dt); | ||
1738 | job->setParentJob(q); | ||||
1713 | Scheduler::setJobPriority(job, 1); | 1739 | Scheduler::setJobPriority(job, 1); | ||
1714 | q->addSubjob(job); | 1740 | q->addSubjob(job); | ||
1715 | 1741 | | |||
1716 | #if 0 // ifdef Q_OS_UNIX | 1742 | #if 0 // ifdef Q_OS_UNIX | ||
1717 | // TODO: can be removed now. Or reintroduced as a fast path for local files | 1743 | // TODO: can be removed now. Or reintroduced as a fast path for local files | ||
1718 | // if launching even more jobs as done above is a performance problem. | 1744 | // if launching even more jobs as done above is a performance problem. | ||
1719 | // | 1745 | // | ||
1720 | QLinkedList<CopyInfo>::const_iterator it = m_directoriesCopied.constBegin(); | 1746 | QLinkedList<CopyInfo>::const_iterator it = m_directoriesCopied.constBegin(); | ||
▲ Show 20 Lines • Show All 528 Lines • Show Last 20 Lines |
mark the method as const