Changeset View
Standalone View
src/core/copyjob.cpp
Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Line(s) | 228 | // KIO::Job* linkNextFile( const QUrl& uSource, const QUrl& uDest, bool overwrite ); | |||
---|---|---|---|---|---|
255 | /** | 255 | /** | ||
256 | * Forward signal from subjob | 256 | * Forward signal from subjob | ||
257 | * @param size the total size | 257 | * @param size the total size | ||
258 | */ | 258 | */ | ||
259 | void slotTotalSize(KJob *, qulonglong size); | 259 | void slotTotalSize(KJob *, qulonglong size); | ||
260 | 260 | | |||
261 | void slotReport(); | 261 | void slotReport(); | ||
262 | 262 | | |||
263 | Q_DECLARE_PUBLIC(CopyJob) | 263 | Q_DECLARE_PUBLIC(CopyJob) | ||
dfaure: mark the method as const | |||||
264 | 264 | | |||
265 | static inline CopyJob *newJob(const QList<QUrl> &src, const QUrl &dest, | 265 | static inline CopyJob *newJob(const QList<QUrl> &src, const QUrl &dest, | ||
266 | CopyJob::CopyMode mode, bool asMethod, JobFlags flags) | 266 | CopyJob::CopyMode mode, bool asMethod, JobFlags flags) | ||
267 | { | 267 | { | ||
268 | CopyJob *job = new CopyJob(*new CopyJobPrivate(src, dest, mode, asMethod)); | 268 | CopyJob *job = new CopyJob(*new CopyJobPrivate(src, dest, mode, asMethod)); | ||
269 | job->setUiDelegate(KIO::createDefaultJobUiDelegate()); | 269 | job->setUiDelegate(KIO::createDefaultJobUiDelegate()); | ||
270 | if (!(flags & HideProgressInfo)) { | 270 | if (!(flags & HideProgressInfo)) { | ||
271 | KIO::getJobTracker()->registerJob(job); | 271 | KIO::getJobTracker()->registerJob(job); | ||
272 | } | 272 | } | ||
273 | if (flags & KIO::Overwrite) { | 273 | if (flags & KIO::Overwrite) { | ||
274 | job->d_func()->m_bOverwriteAllDirs = true; | 274 | job->d_func()->m_bOverwriteAllDirs = true; | ||
275 | job->d_func()->m_bOverwriteAllFiles = true; | 275 | job->d_func()->m_bOverwriteAllFiles = true; | ||
276 | } | 276 | } | ||
277 | if (!(flags & KIO::NoPrivilegeExecution)) { | ||||
278 | job->d_func()->m_privilegeExecutionEnabled = true; | ||||
279 | FileOperationType copyType; | ||||
280 | switch (mode) { | ||||
281 | case CopyJob::Copy: | ||||
282 | copyType = Copy; | ||||
283 | break; | ||||
284 | case CopyJob::Move: | ||||
dfaure: switch() ? | |||||
285 | copyType = Move; | ||||
286 | break; | ||||
287 | case CopyJob::Link: | ||||
288 | copyType = Symlink; | ||||
289 | break; | ||||
290 | } | ||||
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… | |||||
291 | job->d_func()->m_operationType = copyType; | ||||
292 | } | ||||
277 | return job; | 293 | return job; | ||
278 | } | 294 | } | ||
279 | }; | 295 | }; | ||
280 | 296 | | |||
281 | CopyJob::CopyJob(CopyJobPrivate &dd) | 297 | CopyJob::CopyJob(CopyJobPrivate &dd) | ||
282 | : Job(dd) | 298 | : Job(dd) | ||
283 | { | 299 | { | ||
284 | setProperty("destUrl", d_func()->m_dest.toString()); | 300 | setProperty("destUrl", d_func()->m_dest.toString()); | ||
▲ Show 20 Lines • Show All 629 Lines • ▼ Show 20 Line(s) | 906 | { | |||
914 | info.uSource = m_currentSrcURL; | 930 | info.uSource = m_currentSrcURL; | ||
915 | info.uDest = dest; | 931 | info.uDest = dest; | ||
916 | QList<CopyInfo> files; | 932 | QList<CopyInfo> files; | ||
917 | files.append(info); | 933 | files.append(info); | ||
918 | emit q->aboutToCreate(q, files); | 934 | emit q->aboutToCreate(q, files); | ||
919 | 935 | | |||
920 | KIO_ARGS << m_currentSrcURL << dest << (qint8) false /*no overwrite*/; | 936 | KIO_ARGS << m_currentSrcURL << dest << (qint8) false /*no overwrite*/; | ||
921 | SimpleJob *newJob = SimpleJobPrivate::newJobNoUi(slave_url, CMD_RENAME, packedArgs); | 937 | SimpleJob *newJob = SimpleJobPrivate::newJobNoUi(slave_url, CMD_RENAME, packedArgs); | ||
938 | newJob->setParentJob(q); | ||||
922 | Scheduler::setJobPriority(newJob, 1); | 939 | Scheduler::setJobPriority(newJob, 1); | ||
923 | q->addSubjob(newJob); | 940 | q->addSubjob(newJob); | ||
924 | if (m_currentSrcURL.adjusted(QUrl::RemoveFilename) != dest.adjusted(QUrl::RemoveFilename)) { // For the user, moving isn't renaming. Only renaming is. | 941 | if (m_currentSrcURL.adjusted(QUrl::RemoveFilename) != dest.adjusted(QUrl::RemoveFilename)) { // For the user, moving isn't renaming. Only renaming is. | ||
925 | m_bOnlyRenames = false; | 942 | m_bOnlyRenames = false; | ||
926 | } | 943 | } | ||
927 | } | 944 | } | ||
928 | 945 | | |||
929 | void CopyJobPrivate::startListing(const QUrl &src) | 946 | void CopyJobPrivate::startListing(const QUrl &src) | ||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Line(s) | 1233 | } else { | |||
1217 | udir = (*it).uDest; | 1234 | udir = (*it).uDest; | ||
1218 | } | 1235 | } | ||
1219 | } | 1236 | } | ||
1220 | } | 1237 | } | ||
1221 | if (!udir.isEmpty()) { // any dir to create, finally ? | 1238 | if (!udir.isEmpty()) { // any dir to create, finally ? | ||
1222 | // Create the directory - with default permissions so that we can put files into it | 1239 | // Create the directory - with default permissions so that we can put files into it | ||
1223 | // TODO : change permissions once all is finished; but for stuff coming from CDROM it sucks... | 1240 | // TODO : change permissions once all is finished; but for stuff coming from CDROM it sucks... | ||
1224 | KIO::SimpleJob *newjob = KIO::mkdir(udir, -1); | 1241 | KIO::SimpleJob *newjob = KIO::mkdir(udir, -1); | ||
1242 | newjob->setParentJob(q); | ||||
1225 | Scheduler::setJobPriority(newjob, 1); | 1243 | Scheduler::setJobPriority(newjob, 1); | ||
1226 | if (shouldOverwriteFile(udir.path())) { // if we are overwriting an existing file or symlink | 1244 | if (shouldOverwriteFile(udir.path())) { // if we are overwriting an existing file or symlink | ||
1227 | newjob->addMetaData(QStringLiteral("overwrite"), QStringLiteral("true")); | 1245 | newjob->addMetaData(QStringLiteral("overwrite"), QStringLiteral("true")); | ||
1228 | } | 1246 | } | ||
1229 | 1247 | | |||
1230 | m_currentDestURL = udir; | 1248 | m_currentDestURL = udir; | ||
1231 | m_bURLDirty = true; | 1249 | m_bURLDirty = true; | ||
1232 | 1250 | | |||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 1335 | } else { // no error | |||
1319 | if (m_bCurrentOperationIsLink && m_mode == CopyJob::Move | 1337 | if (m_bCurrentOperationIsLink && m_mode == CopyJob::Move | ||
1320 | && !qobject_cast<KIO::DeleteJob *>(job) // Deleting source not already done | 1338 | && !qobject_cast<KIO::DeleteJob *>(job) // Deleting source not already done | ||
1321 | ) { | 1339 | ) { | ||
1322 | q->removeSubjob(job); | 1340 | q->removeSubjob(job); | ||
1323 | assert(!q->hasSubjobs()); | 1341 | assert(!q->hasSubjobs()); | ||
1324 | // The only problem with this trick is that the error handling for this del operation | 1342 | // The only problem with this trick is that the error handling for this del operation | ||
1325 | // is not going to be right... see 'Very special case' above. | 1343 | // is not going to be right... see 'Very special case' above. | ||
1326 | KIO::Job *newjob = KIO::del((*it).uSource, HideProgressInfo); | 1344 | KIO::Job *newjob = KIO::del((*it).uSource, HideProgressInfo); | ||
1345 | newjob->setParentJob(q); | ||||
1327 | q->addSubjob(newjob); | 1346 | q->addSubjob(newjob); | ||
1328 | return; // Don't move to next file yet ! | 1347 | return; // Don't move to next file yet ! | ||
1329 | } | 1348 | } | ||
1330 | 1349 | | |||
1331 | const QUrl finalUrl = finalDestUrl((*it).uSource, (*it).uDest); | 1350 | const QUrl finalUrl = finalDestUrl((*it).uSource, (*it).uDest); | ||
1332 | 1351 | | |||
1333 | if (m_bCurrentOperationIsLink) { | 1352 | if (m_bCurrentOperationIsLink) { | ||
1334 | QString target = (m_mode == CopyJob::Link ? (*it).uSource.path() : (*it).linkDest); | 1353 | QString target = (m_mode == CopyJob::Link ? (*it).uSource.path() : (*it).linkDest); | ||
▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | 1512 | { | |||
1495 | if ( | 1514 | if ( | ||
1496 | (uSource.scheme() == uDest.scheme()) && | 1515 | (uSource.scheme() == uDest.scheme()) && | ||
1497 | (uSource.host() == uDest.host()) && | 1516 | (uSource.host() == uDest.host()) && | ||
1498 | (uSource.port() == uDest.port()) && | 1517 | (uSource.port() == uDest.port()) && | ||
1499 | (uSource.userName() == uDest.userName()) && | 1518 | (uSource.userName() == uDest.userName()) && | ||
1500 | (uSource.password() == uDest.password())) { | 1519 | (uSource.password() == uDest.password())) { | ||
1501 | // This is the case of creating a real symlink | 1520 | // This is the case of creating a real symlink | ||
1502 | KIO::SimpleJob *newJob = KIO::symlink(uSource.path(), uDest, flags | HideProgressInfo /*no GUI*/); | 1521 | KIO::SimpleJob *newJob = KIO::symlink(uSource.path(), uDest, flags | HideProgressInfo /*no GUI*/); | ||
1522 | newJob->setParentJob(q_func()); | ||||
1503 | Scheduler::setJobPriority(newJob, 1); | 1523 | Scheduler::setJobPriority(newJob, 1); | ||
1504 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << uSource.path() << "link=" << uDest; | 1524 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << uSource.path() << "link=" << uDest; | ||
1505 | //emit linking( this, uSource.path(), uDest ); | 1525 | //emit linking( this, uSource.path(), uDest ); | ||
1506 | m_bCurrentOperationIsLink = true; | 1526 | m_bCurrentOperationIsLink = true; | ||
1507 | m_currentSrcURL = uSource; | 1527 | m_currentSrcURL = uSource; | ||
1508 | m_currentDestURL = uDest; | 1528 | m_currentDestURL = uDest; | ||
1509 | m_bURLDirty = true; | 1529 | m_bURLDirty = true; | ||
1510 | //Observer::self()->slotCopying( this, uSource, uDest ); // should be slotLinking perhaps | 1530 | //Observer::self()->slotCopying( this, uSource, uDest ); // should be slotLinking perhaps | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 1641 | } else if (!(*it).linkDest.isEmpty() && | |||
1622 | (uSource.scheme() == uDest.scheme()) && | 1642 | (uSource.scheme() == uDest.scheme()) && | ||
1623 | (uSource.host() == uDest.host()) && | 1643 | (uSource.host() == uDest.host()) && | ||
1624 | (uSource.port() == uDest.port()) && | 1644 | (uSource.port() == uDest.port()) && | ||
1625 | (uSource.userName() == uDest.userName()) && | 1645 | (uSource.userName() == uDest.userName()) && | ||
1626 | (uSource.password() == uDest.password())) | 1646 | (uSource.password() == uDest.password())) | ||
1627 | // Copying a symlink - only on the same protocol/host/etc. (#5601, downloading an FTP file through its link), | 1647 | // Copying a symlink - only on the same protocol/host/etc. (#5601, downloading an FTP file through its link), | ||
1628 | { | 1648 | { | ||
1629 | KIO::SimpleJob *newJob = KIO::symlink((*it).linkDest, uDest, flags | HideProgressInfo /*no GUI*/); | 1649 | KIO::SimpleJob *newJob = KIO::symlink((*it).linkDest, uDest, flags | HideProgressInfo /*no GUI*/); | ||
1650 | newJob->setParentJob(q); | ||||
1630 | Scheduler::setJobPriority(newJob, 1); | 1651 | Scheduler::setJobPriority(newJob, 1); | ||
1631 | newjob = newJob; | 1652 | newjob = newJob; | ||
1632 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << (*it).linkDest << "link=" << uDest; | 1653 | qCDebug(KIO_COPYJOB_DEBUG) << "Linking target=" << (*it).linkDest << "link=" << uDest; | ||
1633 | m_currentSrcURL = QUrl::fromUserInput((*it).linkDest); | 1654 | m_currentSrcURL = QUrl::fromUserInput((*it).linkDest); | ||
1634 | m_currentDestURL = uDest; | 1655 | m_currentDestURL = uDest; | ||
1635 | m_bURLDirty = true; | 1656 | m_bURLDirty = true; | ||
1636 | //emit linking( this, (*it).linkDest, uDest ); | 1657 | //emit linking( this, (*it).linkDest, uDest ); | ||
1637 | //Observer::self()->slotCopying( this, m_currentSrcURL, uDest ); // should be slotLinking perhaps | 1658 | //Observer::self()->slotCopying( this, m_currentSrcURL, uDest ); // should be slotLinking perhaps | ||
1638 | m_bCurrentOperationIsLink = true; | 1659 | m_bCurrentOperationIsLink = true; | ||
1639 | // NOTE: if we are moving stuff, the deletion of the source will be done in slotResultCopyingFiles | 1660 | // NOTE: if we are moving stuff, the deletion of the source will be done in slotResultCopyingFiles | ||
1640 | } else if (m_mode == CopyJob::Move) { // Moving a file | 1661 | } else if (m_mode == CopyJob::Move) { // Moving a file | ||
1641 | KIO::FileCopyJob *moveJob = KIO::file_move(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/); | 1662 | KIO::FileCopyJob *moveJob = KIO::file_move(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/); | ||
1663 | moveJob->setParentJob(q); | ||||
1642 | moveJob->setSourceSize((*it).size); | 1664 | moveJob->setSourceSize((*it).size); | ||
1643 | moveJob->setModificationTime((*it).mtime); // #55804 | 1665 | moveJob->setModificationTime((*it).mtime); // #55804 | ||
1644 | newjob = moveJob; | 1666 | newjob = moveJob; | ||
1645 | qCDebug(KIO_COPYJOB_DEBUG) << "Moving" << uSource << "to" << uDest; | 1667 | qCDebug(KIO_COPYJOB_DEBUG) << "Moving" << uSource << "to" << uDest; | ||
1646 | //emit moving( this, uSource, uDest ); | 1668 | //emit moving( this, uSource, uDest ); | ||
1647 | m_currentSrcURL = uSource; | 1669 | m_currentSrcURL = uSource; | ||
1648 | m_currentDestURL = uDest; | 1670 | m_currentDestURL = uDest; | ||
1649 | m_bURLDirty = true; | 1671 | m_bURLDirty = true; | ||
1650 | //Observer::self()->slotMoving( this, uSource, uDest ); | 1672 | //Observer::self()->slotMoving( this, uSource, uDest ); | ||
1651 | } else { // Copying a file | 1673 | } else { // Copying a file | ||
1652 | KIO::FileCopyJob *copyJob = KIO::file_copy(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/); | 1674 | KIO::FileCopyJob *copyJob = KIO::file_copy(uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/); | ||
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… | |||||
1653 | copyJob->setParentJob(q); // in case of rename dialog | 1675 | copyJob->setParentJob(q); // in case of rename dialog | ||
1654 | copyJob->setSourceSize((*it).size); | 1676 | copyJob->setSourceSize((*it).size); | ||
1655 | copyJob->setModificationTime((*it).mtime); | 1677 | copyJob->setModificationTime((*it).mtime); | ||
1656 | newjob = copyJob; | 1678 | newjob = copyJob; | ||
1657 | qCDebug(KIO_COPYJOB_DEBUG) << "Copying" << uSource << "to" << uDest; | 1679 | qCDebug(KIO_COPYJOB_DEBUG) << "Copying" << uSource << "to" << uDest; | ||
1658 | m_currentSrcURL = uSource; | 1680 | m_currentSrcURL = uSource; | ||
1659 | m_currentDestURL = uDest; | 1681 | m_currentDestURL = uDest; | ||
1660 | m_bURLDirty = true; | 1682 | m_bURLDirty = true; | ||
Show All 14 Lines | |||||
1675 | { | 1697 | { | ||
1676 | Q_Q(CopyJob); | 1698 | Q_Q(CopyJob); | ||
1677 | if (m_mode == CopyJob::Move && !dirsToRemove.isEmpty()) { // some dirs to delete ? | 1699 | if (m_mode == CopyJob::Move && !dirsToRemove.isEmpty()) { // some dirs to delete ? | ||
1678 | state = STATE_DELETING_DIRS; | 1700 | state = STATE_DELETING_DIRS; | ||
1679 | m_bURLDirty = true; | 1701 | m_bURLDirty = true; | ||
1680 | // Take first dir to delete out of list - last ones first ! | 1702 | // Take first dir to delete out of list - last ones first ! | ||
1681 | QList<QUrl>::Iterator it = --dirsToRemove.end(); | 1703 | QList<QUrl>::Iterator it = --dirsToRemove.end(); | ||
1682 | SimpleJob *job = KIO::rmdir(*it); | 1704 | SimpleJob *job = KIO::rmdir(*it); | ||
1705 | job->setParentJob(q); | ||||
1683 | Scheduler::setJobPriority(job, 1); | 1706 | Scheduler::setJobPriority(job, 1); | ||
1684 | dirsToRemove.erase(it); | 1707 | dirsToRemove.erase(it); | ||
1685 | q->addSubjob(job); | 1708 | q->addSubjob(job); | ||
1686 | } else { | 1709 | } else { | ||
1687 | // This step is done, move on | 1710 | // This step is done, move on | ||
1688 | state = STATE_SETTING_DIR_ATTRIBUTES; | 1711 | state = STATE_SETTING_DIR_ATTRIBUTES; | ||
1689 | m_directoriesCopiedIterator = m_directoriesCopied.constBegin(); | 1712 | m_directoriesCopiedIterator = m_directoriesCopied.constBegin(); | ||
1690 | setNextDirAttribute(); | 1713 | setNextDirAttribute(); | ||
1691 | } | 1714 | } | ||
1692 | } | 1715 | } | ||
1693 | 1716 | | |||
1694 | void CopyJobPrivate::setNextDirAttribute() | 1717 | void CopyJobPrivate::setNextDirAttribute() | ||
1695 | { | 1718 | { | ||
1696 | Q_Q(CopyJob); | 1719 | Q_Q(CopyJob); | ||
1697 | while (m_directoriesCopiedIterator != m_directoriesCopied.constEnd() && | 1720 | while (m_directoriesCopiedIterator != m_directoriesCopied.constEnd() && | ||
1698 | !(*m_directoriesCopiedIterator).mtime.isValid()) { | 1721 | !(*m_directoriesCopiedIterator).mtime.isValid()) { | ||
1699 | ++m_directoriesCopiedIterator; | 1722 | ++m_directoriesCopiedIterator; | ||
1700 | } | 1723 | } | ||
1701 | if (m_directoriesCopiedIterator != m_directoriesCopied.constEnd()) { | 1724 | if (m_directoriesCopiedIterator != m_directoriesCopied.constEnd()) { | ||
1702 | const QUrl url = (*m_directoriesCopiedIterator).uDest; | 1725 | const QUrl url = (*m_directoriesCopiedIterator).uDest; | ||
1703 | const QDateTime dt = (*m_directoriesCopiedIterator).mtime; | 1726 | const QDateTime dt = (*m_directoriesCopiedIterator).mtime; | ||
1704 | ++m_directoriesCopiedIterator; | 1727 | ++m_directoriesCopiedIterator; | ||
1705 | 1728 | | |||
1706 | KIO::SimpleJob *job = KIO::setModificationTime(url, dt); | 1729 | KIO::SimpleJob *job = KIO::setModificationTime(url, dt); | ||
1730 | job->setParentJob(q); | ||||
1707 | Scheduler::setJobPriority(job, 1); | 1731 | Scheduler::setJobPriority(job, 1); | ||
1708 | q->addSubjob(job); | 1732 | q->addSubjob(job); | ||
1709 | 1733 | | |||
1710 | #if 0 // ifdef Q_OS_UNIX | 1734 | #if 0 // ifdef Q_OS_UNIX | ||
1711 | // TODO: can be removed now. Or reintroduced as a fast path for local files | 1735 | // TODO: can be removed now. Or reintroduced as a fast path for local files | ||
1712 | // if launching even more jobs as done above is a performance problem. | 1736 | // if launching even more jobs as done above is a performance problem. | ||
1713 | // | 1737 | // | ||
1714 | QLinkedList<CopyInfo>::const_iterator it = m_directoriesCopied.constBegin(); | 1738 | QLinkedList<CopyInfo>::const_iterator it = m_directoriesCopied.constBegin(); | ||
▲ Show 20 Lines • Show All 528 Lines • Show Last 20 Lines |
mark the method as const