• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • kio
copyjob.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright 2000 Stephan Kulow <coolo@kde.org>
3  Copyright 2000-2006 David Faure <faure@kde.org>
4  Copyright 2000 Waldo Bastian <bastian@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "copyjob.h"
23 #include <errno.h>
24 #include "kdirlister.h"
25 #include "kfileitem.h"
26 #include "deletejob.h"
27 #include "clipboardupdater_p.h"
28 
29 #include <klocale.h>
30 #include <kdesktopfile.h>
31 #include <kdebug.h>
32 #include <kde_file.h>
33 
34 #include "slave.h"
35 #include "scheduler.h"
36 #include "kdirwatch.h"
37 #include "kprotocolmanager.h"
38 
39 #include "jobuidelegate.h"
40 
41 #include <kdirnotify.h>
42 #include <ktemporaryfile.h>
43 
44 #ifdef Q_OS_UNIX
45 #include <utime.h>
46 #endif
47 #include <assert.h>
48 
49 #include <QtCore/QTimer>
50 #include <QtCore/QFile>
51 #include <sys/stat.h> // mode_t
52 #include <QPointer>
53 
54 #include "job_p.h"
55 #include <kdiskfreespaceinfo.h>
56 #include <kfilesystemtype_p.h>
57 
58 using namespace KIO;
59 
60 //this will update the report dialog with 5 Hz, I think this is fast enough, aleXXX
61 #define REPORT_TIMEOUT 200
62 
63 enum DestinationState {
64  DEST_NOT_STATED,
65  DEST_IS_DIR,
66  DEST_IS_FILE,
67  DEST_DOESNT_EXIST
68 };
69 
86 enum CopyJobState {
87  STATE_STATING,
88  STATE_RENAMING,
89  STATE_LISTING,
90  STATE_CREATING_DIRS,
91  STATE_CONFLICT_CREATING_DIRS,
92  STATE_COPYING_FILES,
93  STATE_CONFLICT_COPYING_FILES,
94  STATE_DELETING_DIRS,
95  STATE_SETTING_DIR_ATTRIBUTES
96 };
97 
99 class KIO::CopyJobPrivate: public KIO::JobPrivate
100 {
101 public:
102  CopyJobPrivate(const KUrl::List& src, const KUrl& dest,
103  CopyJob::CopyMode mode, bool asMethod)
104  : m_globalDest(dest)
105  , m_globalDestinationState(DEST_NOT_STATED)
106  , m_defaultPermissions(false)
107  , m_bURLDirty(false)
108  , m_mode(mode)
109  , m_asMethod(asMethod)
110  , destinationState(DEST_NOT_STATED)
111  , state(STATE_STATING)
112  , m_freeSpace(-1)
113  , m_totalSize(0)
114  , m_processedSize(0)
115  , m_fileProcessedSize(0)
116  , m_processedFiles(0)
117  , m_processedDirs(0)
118  , m_srcList(src)
119  , m_currentStatSrc(m_srcList.constBegin())
120  , m_bCurrentOperationIsLink(false)
121  , m_bSingleFileCopy(false)
122  , m_bOnlyRenames(mode==CopyJob::Move)
123  , m_dest(dest)
124  , m_bAutoRenameFiles(false)
125  , m_bAutoRenameDirs(false)
126  , m_bAutoSkipFiles( false )
127  , m_bAutoSkipDirs( false )
128  , m_bOverwriteAllFiles( false )
129  , m_bOverwriteAllDirs( false )
130  , m_conflictError(0)
131  , m_reportTimer(0)
132  {
133  }
134 
135  // This is the dest URL that was initially given to CopyJob
136  // It is copied into m_dest, which can be changed for a given src URL
137  // (when using the RENAME dialog in slotResult),
138  // and which will be reset for the next src URL.
139  KUrl m_globalDest;
140  // The state info about that global dest
141  DestinationState m_globalDestinationState;
142  // See setDefaultPermissions
143  bool m_defaultPermissions;
144  // Whether URLs changed (and need to be emitted by the next slotReport call)
145  bool m_bURLDirty;
146  // Used after copying all the files into the dirs, to set mtime (TODO: and permissions?)
147  // after the copy is done
148  QLinkedList<CopyInfo> m_directoriesCopied;
149  QLinkedList<CopyInfo>::const_iterator m_directoriesCopiedIterator;
150 
151  CopyJob::CopyMode m_mode;
152  bool m_asMethod;
153  DestinationState destinationState;
154  CopyJobState state;
155 
156  KIO::filesize_t m_freeSpace;
157 
158  KIO::filesize_t m_totalSize;
159  KIO::filesize_t m_processedSize;
160  KIO::filesize_t m_fileProcessedSize;
161  int m_processedFiles;
162  int m_processedDirs;
163  QList<CopyInfo> files;
164  QList<CopyInfo> dirs;
165  KUrl::List dirsToRemove;
166  KUrl::List m_srcList;
167  KUrl::List m_successSrcList; // Entries in m_srcList that have successfully been moved
168  KUrl::List::const_iterator m_currentStatSrc;
169  bool m_bCurrentSrcIsDir;
170  bool m_bCurrentOperationIsLink;
171  bool m_bSingleFileCopy;
172  bool m_bOnlyRenames;
173  KUrl m_dest;
174  KUrl m_currentDest; // set during listing, used by slotEntries
175  //
176  QStringList m_skipList;
177  QSet<QString> m_overwriteList;
178  bool m_bAutoRenameFiles;
179  bool m_bAutoRenameDirs;
180  bool m_bAutoSkipFiles;
181  bool m_bAutoSkipDirs;
182  bool m_bOverwriteAllFiles;
183  bool m_bOverwriteAllDirs;
184  int m_conflictError;
185 
186  QTimer *m_reportTimer;
187 
188  // The current src url being stat'ed or copied
189  // During the stat phase, this is initially equal to *m_currentStatSrc but it can be resolved to a local file equivalent (#188903).
190  KUrl m_currentSrcURL;
191  KUrl m_currentDestURL;
192 
193  QSet<QString> m_parentDirs;
194 
195  void statCurrentSrc();
196  void statNextSrc();
197 
198  // Those aren't slots but submethods for slotResult.
199  void slotResultStating( KJob * job );
200  void startListing( const KUrl & src );
201  void slotResultCreatingDirs( KJob * job );
202  void slotResultConflictCreatingDirs( KJob * job );
203  void createNextDir();
204  void slotResultCopyingFiles( KJob * job );
205  void slotResultConflictCopyingFiles( KJob * job );
206 // KIO::Job* linkNextFile( const KUrl& uSource, const KUrl& uDest, bool overwrite );
207  KIO::Job* linkNextFile( const KUrl& uSource, const KUrl& uDest, JobFlags flags );
208  void copyNextFile();
209  void slotResultDeletingDirs( KJob * job );
210  void deleteNextDir();
211  void sourceStated(const UDSEntry& entry, const KUrl& sourceUrl);
212  void skip(const KUrl & sourceURL, bool isDir);
213  void slotResultRenaming( KJob * job );
214  void slotResultSettingDirAttributes( KJob * job );
215  void setNextDirAttribute();
216 
217  void startRenameJob(const KUrl &slave_url);
218  bool shouldOverwriteDir( const QString& path ) const;
219  bool shouldOverwriteFile( const QString& path ) const;
220  bool shouldSkip( const QString& path ) const;
221  void skipSrc(bool isDir);
222 
223  void slotStart();
224  void slotEntries( KIO::Job*, const KIO::UDSEntryList& list );
225  void slotSubError(KIO::ListJob* job, KIO::ListJob *subJob);
226  void addCopyInfoFromUDSEntry(const UDSEntry& entry, const KUrl& srcUrl, bool srcIsDir, const KUrl& currentDest);
230  void slotProcessedSize( KJob*, qulonglong data_size );
235  void slotTotalSize( KJob*, qulonglong size );
236 
237  void slotReport();
238 
239  Q_DECLARE_PUBLIC(CopyJob)
240 
241  static inline CopyJob *newJob(const KUrl::List& src, const KUrl& dest,
242  CopyJob::CopyMode mode, bool asMethod, JobFlags flags)
243  {
244  CopyJob *job = new CopyJob(*new CopyJobPrivate(src,dest,mode,asMethod));
245  job->setUiDelegate(new JobUiDelegate);
246  if (!(flags & HideProgressInfo))
247  KIO::getJobTracker()->registerJob(job);
248  if (flags & KIO::Overwrite) {
249  job->d_func()->m_bOverwriteAllDirs = true;
250  job->d_func()->m_bOverwriteAllFiles = true;
251  }
252  return job;
253  }
254 };
255 
256 CopyJob::CopyJob(CopyJobPrivate &dd)
257  : Job(dd)
258 {
259  setProperty("destUrl", d_func()->m_dest.url());
260  QTimer::singleShot(0, this, SLOT(slotStart()));
261  qRegisterMetaType<KIO::UDSEntry>("KIO::UDSEntry");
262 }
263 
264 CopyJob::~CopyJob()
265 {
266 }
267 
268 KUrl::List CopyJob::srcUrls() const
269 {
270  return d_func()->m_srcList;
271 }
272 
273 KUrl CopyJob::destUrl() const
274 {
275  return d_func()->m_dest;
276 }
277 
278 void CopyJobPrivate::slotStart()
279 {
280  Q_Q(CopyJob);
286  m_reportTimer = new QTimer(q);
287 
288  q->connect(m_reportTimer,SIGNAL(timeout()),q,SLOT(slotReport()));
289  m_reportTimer->start(REPORT_TIMEOUT);
290 
291  // Stat the dest
292  KIO::Job * job = KIO::stat( m_dest, StatJob::DestinationSide, 2, KIO::HideProgressInfo );
293  //kDebug(7007) << "CopyJob:stating the dest " << m_dest;
294  q->addSubjob(job);
295 }
296 
297 // For unit test purposes
298 KIO_EXPORT bool kio_resolve_local_urls = true;
299 
300 void CopyJobPrivate::slotResultStating( KJob *job )
301 {
302  Q_Q(CopyJob);
303  //kDebug(7007);
304  // Was there an error while stating the src ?
305  if (job->error() && destinationState != DEST_NOT_STATED )
306  {
307  const KUrl srcurl = static_cast<SimpleJob*>(job)->url();
308  if ( !srcurl.isLocalFile() )
309  {
310  // Probably : src doesn't exist. Well, over some protocols (e.g. FTP)
311  // this info isn't really reliable (thanks to MS FTP servers).
312  // We'll assume a file, and try to download anyway.
313  kDebug(7007) << "Error while stating source. Activating hack";
314  q->removeSubjob( job );
315  assert ( !q->hasSubjobs() ); // We should have only one job at a time ...
316  struct CopyInfo info;
317  info.permissions = (mode_t) -1;
318  info.mtime = (time_t) -1;
319  info.ctime = (time_t) -1;
320  info.size = (KIO::filesize_t)-1;
321  info.uSource = srcurl;
322  info.uDest = m_dest;
323  // Append filename or dirname to destination URL, if allowed
324  if ( destinationState == DEST_IS_DIR && !m_asMethod )
325  info.uDest.addPath( srcurl.fileName() );
326 
327  files.append( info );
328  statNextSrc();
329  return;
330  }
331  // Local file. If stat fails, the file definitely doesn't exist.
332  // yes, q->Job::, because we don't want to call our override
333  q->Job::slotResult( job ); // will set the error and emit result(this)
334  return;
335  }
336 
337  // Keep copy of the stat result
338  const UDSEntry entry = static_cast<StatJob*>(job)->statResult();
339 
340  if ( destinationState == DEST_NOT_STATED ) {
341  if ( m_dest.isLocalFile() ) { //works for dirs as well
342  QString path = m_dest.toLocalFile();
343  if (m_asMethod) {
344  // In copy-as mode, we want to check the directory to which we're
345  // copying. The target file or directory does not exist yet, which
346  // might confuse KDiskFreeSpaceInfo.
347  path = QFileInfo(path).absolutePath();
348  }
349  KFileSystemType::Type fsType = KFileSystemType::fileSystemType( path );
350  if ( fsType != KFileSystemType::Nfs && fsType != KFileSystemType::Smb && fsType != KFileSystemType::Ramfs ) {
351  m_freeSpace = KDiskFreeSpaceInfo::freeSpaceInfo( path ).available();
352  }
353  //TODO actually preliminary check is even more valuable for slow NFS/SMB mounts,
354  //but we need to find a way to report connection errors to user
355  }
356 
357  const bool isGlobalDest = m_dest == m_globalDest;
358  const bool isDir = entry.isDir();
359  // we were stating the dest
360  if (job->error()) {
361  destinationState = DEST_DOESNT_EXIST;
362  //kDebug(7007) << "dest does not exist";
363  } else {
364  // Treat symlinks to dirs as dirs here, so no test on isLink
365  destinationState = isDir ? DEST_IS_DIR : DEST_IS_FILE;
366  //kDebug(7007) << "dest is dir:" << isDir;
367 
368  const QString sLocalPath = entry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
369  if ( !sLocalPath.isEmpty() && kio_resolve_local_urls && destinationState != DEST_DOESNT_EXIST ) {
370  m_dest = KUrl();
371  m_dest.setPath(sLocalPath);
372  if ( isGlobalDest )
373  m_globalDest = m_dest;
374  }
375  }
376  if ( isGlobalDest )
377  m_globalDestinationState = destinationState;
378 
379  q->removeSubjob( job );
380  assert ( !q->hasSubjobs() );
381 
382  // After knowing what the dest is, we can start stat'ing the first src.
383  statCurrentSrc();
384  } else {
385  sourceStated(entry, static_cast<SimpleJob*>(job)->url());
386  q->removeSubjob( job );
387  }
388 }
389 
390 void CopyJobPrivate::sourceStated(const UDSEntry& entry, const KUrl& sourceUrl)
391 {
392  const QString sLocalPath = entry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
393  const bool isDir = entry.isDir();
394 
395  // We were stating the current source URL
396  // Is it a file or a dir ?
397 
398  // There 6 cases, and all end up calling addCopyInfoFromUDSEntry first :
399  // 1 - src is a dir, destination is a directory,
400  // slotEntries will append the source-dir-name to the destination
401  // 2 - src is a dir, destination is a file -- will offer to overwrite, later on.
402  // 3 - src is a dir, destination doesn't exist, then it's the destination dirname,
403  // so slotEntries will use it as destination.
404 
405  // 4 - src is a file, destination is a directory,
406  // slotEntries will append the filename to the destination.
407  // 5 - src is a file, destination is a file, m_dest is the exact destination name
408  // 6 - src is a file, destination doesn't exist, m_dest is the exact destination name
409 
410  KUrl srcurl;
411  if (!sLocalPath.isEmpty() && destinationState != DEST_DOESNT_EXIST) {
412  kDebug() << "Using sLocalPath. destinationState=" << destinationState;
413  // Prefer the local path -- but only if we were able to stat() the dest.
414  // Otherwise, renaming a desktop:/ url would copy from src=file to dest=desktop (#218719)
415  srcurl.setPath(sLocalPath);
416  } else {
417  srcurl = sourceUrl;
418  }
419  addCopyInfoFromUDSEntry(entry, srcurl, false, m_dest);
420 
421  m_currentDest = m_dest;
422  m_bCurrentSrcIsDir = false;
423 
424  if ( isDir
425  // treat symlinks as files (no recursion)
426  && !entry.isLink()
427  && m_mode != CopyJob::Link ) // No recursion in Link mode either.
428  {
429  //kDebug(7007) << "Source is a directory";
430 
431  if (srcurl.isLocalFile()) {
432  const QString parentDir = srcurl.toLocalFile(KUrl::RemoveTrailingSlash);
433  m_parentDirs.insert(parentDir);
434  }
435 
436  m_bCurrentSrcIsDir = true; // used by slotEntries
437  if ( destinationState == DEST_IS_DIR ) // (case 1)
438  {
439  if ( !m_asMethod )
440  {
441  // Use <desturl>/<directory_copied> as destination, from now on
442  QString directory = srcurl.fileName();
443  const QString sName = entry.stringValue( KIO::UDSEntry::UDS_NAME );
444  KProtocolInfo::FileNameUsedForCopying fnu = KProtocolManager::fileNameUsedForCopying(srcurl);
445  if (fnu == KProtocolInfo::Name) {
446  if (!sName.isEmpty())
447  directory = sName;
448  } else if (fnu == KProtocolInfo::DisplayName) {
449  const QString dispName = entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_NAME );
450  if (!dispName.isEmpty())
451  directory = dispName;
452  else if (!sName.isEmpty())
453  directory = sName;
454  }
455  m_currentDest.addPath( directory );
456  }
457  }
458  else // (case 3)
459  {
460  // otherwise dest is new name for toplevel dir
461  // so the destination exists, in fact, from now on.
462  // (This even works with other src urls in the list, since the
463  // dir has effectively been created)
464  destinationState = DEST_IS_DIR;
465  if ( m_dest == m_globalDest )
466  m_globalDestinationState = destinationState;
467  }
468 
469  startListing( srcurl );
470  }
471  else
472  {
473  //kDebug(7007) << "Source is a file (or a symlink), or we are linking -> no recursive listing";
474 
475  if (srcurl.isLocalFile()) {
476  const QString parentDir = srcurl.directory(KUrl::ObeyTrailingSlash);
477  m_parentDirs.insert(parentDir);
478  }
479 
480  statNextSrc();
481  }
482 }
483 
484 bool CopyJob::doSuspend()
485 {
486  Q_D(CopyJob);
487  d->slotReport();
488  return Job::doSuspend();
489 }
490 
491 void CopyJobPrivate::slotReport()
492 {
493  Q_Q(CopyJob);
494  if ( q->isSuspended() )
495  return;
496  // If showProgressInfo was set, progressId() is > 0.
497  switch (state) {
498  case STATE_RENAMING:
499  q->setTotalAmount(KJob::Files, m_srcList.count());
500  // fall-through intended
501  case STATE_COPYING_FILES:
502  q->setProcessedAmount( KJob::Files, m_processedFiles );
503  if (m_bURLDirty)
504  {
505  // Only emit urls when they changed. This saves time, and fixes #66281
506  m_bURLDirty = false;
507  if (m_mode==CopyJob::Move)
508  {
509  emitMoving(q, m_currentSrcURL, m_currentDestURL);
510  emit q->moving( q, m_currentSrcURL, m_currentDestURL);
511  }
512  else if (m_mode==CopyJob::Link)
513  {
514  emitCopying( q, m_currentSrcURL, m_currentDestURL ); // we don't have a delegate->linking
515  emit q->linking( q, m_currentSrcURL.path(), m_currentDestURL );
516  }
517  else
518  {
519  emitCopying( q, m_currentSrcURL, m_currentDestURL );
520  emit q->copying( q, m_currentSrcURL, m_currentDestURL );
521  }
522  }
523  break;
524 
525  case STATE_CREATING_DIRS:
526  q->setProcessedAmount( KJob::Directories, m_processedDirs );
527  if (m_bURLDirty)
528  {
529  m_bURLDirty = false;
530  emit q->creatingDir( q, m_currentDestURL );
531  emitCreatingDir( q, m_currentDestURL );
532  }
533  break;
534 
535  case STATE_STATING:
536  case STATE_LISTING:
537  if (m_bURLDirty)
538  {
539  m_bURLDirty = false;
540  if (m_mode==CopyJob::Move)
541  {
542  emitMoving( q, m_currentSrcURL, m_currentDestURL );
543  }
544  else
545  {
546  emitCopying( q, m_currentSrcURL, m_currentDestURL );
547  }
548  }
549  q->setTotalAmount(KJob::Bytes, m_totalSize);
550  q->setTotalAmount(KJob::Files, files.count());
551  q->setTotalAmount(KJob::Directories, dirs.count());
552  break;
553 
554  default:
555  break;
556  }
557 }
558 
559 void CopyJobPrivate::slotEntries(KIO::Job* job, const UDSEntryList& list)
560 {
561  //Q_Q(CopyJob);
562  UDSEntryList::ConstIterator it = list.constBegin();
563  UDSEntryList::ConstIterator end = list.constEnd();
564  for (; it != end; ++it) {
565  const UDSEntry& entry = *it;
566  addCopyInfoFromUDSEntry(entry, static_cast<SimpleJob *>(job)->url(), m_bCurrentSrcIsDir, m_currentDest);
567  }
568 }
569 
570 void CopyJobPrivate::slotSubError(ListJob* job, ListJob* subJob)
571 {
572  const KUrl url = subJob->url();
573  kWarning() << url << subJob->errorString();
574 
575  Q_Q(CopyJob);
576 
577  emit q->warning(job, subJob->errorString(), QString());
578  skip(url, true);
579 }
580 
581 
582 void CopyJobPrivate::addCopyInfoFromUDSEntry(const UDSEntry& entry, const KUrl& srcUrl, bool srcIsDir, const KUrl& currentDest)
583 {
584  struct CopyInfo info;
585  info.permissions = entry.numberValue(KIO::UDSEntry::UDS_ACCESS, -1);
586  info.mtime = (time_t) entry.numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, -1);
587  info.ctime = (time_t) entry.numberValue(KIO::UDSEntry::UDS_CREATION_TIME, -1);
588  info.size = (KIO::filesize_t) entry.numberValue(KIO::UDSEntry::UDS_SIZE, -1);
589  if (info.size != (KIO::filesize_t) -1)
590  m_totalSize += info.size;
591 
592  // recursive listing, displayName can be a/b/c/d
593  const QString fileName = entry.stringValue(KIO::UDSEntry::UDS_NAME);
594  const QString urlStr = entry.stringValue(KIO::UDSEntry::UDS_URL);
595  KUrl url;
596  if (!urlStr.isEmpty())
597  url = urlStr;
598  QString localPath = entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
599  const bool isDir = entry.isDir();
600  info.linkDest = entry.stringValue(KIO::UDSEntry::UDS_LINK_DEST);
601 
602  if (fileName != QLatin1String("..") && fileName != QLatin1String(".")) {
603  const bool hasCustomURL = !url.isEmpty() || !localPath.isEmpty();
604  if (!hasCustomURL) {
605  // Make URL from displayName
606  url = srcUrl;
607  if (srcIsDir) { // Only if src is a directory. Otherwise uSource is fine as is
608  //kDebug(7007) << "adding path" << displayName;
609  url.addPath(fileName);
610  }
611  }
612  //kDebug(7007) << "displayName=" << displayName << "url=" << url;
613  if (!localPath.isEmpty() && kio_resolve_local_urls && destinationState != DEST_DOESNT_EXIST) {
614  url = KUrl(localPath);
615  }
616 
617  info.uSource = url;
618  info.uDest = currentDest;
619  //kDebug(7007) << "uSource=" << info.uSource << "uDest(1)=" << info.uDest;
620  // Append filename or dirname to destination URL, if allowed
621  if (destinationState == DEST_IS_DIR &&
622  // "copy/move as <foo>" means 'foo' is the dest for the base srcurl
623  // (passed here during stating) but not its children (during listing)
624  (! (m_asMethod && state == STATE_STATING)))
625  {
626  QString destFileName;
627  KProtocolInfo::FileNameUsedForCopying fnu = KProtocolManager::fileNameUsedForCopying(url);
628  if (hasCustomURL &&
629  fnu == KProtocolInfo::FromUrl) {
630  //destFileName = url.fileName(); // Doesn't work for recursive listing
631  // Count the number of prefixes used by the recursive listjob
632  int numberOfSlashes = fileName.count('/'); // don't make this a find()!
633  QString path = url.path();
634  int pos = 0;
635  for (int n = 0; n < numberOfSlashes + 1; ++n) {
636  pos = path.lastIndexOf('/', pos - 1);
637  if (pos == -1) { // error
638  kWarning(7007) << "kioslave bug: not enough slashes in UDS_URL" << path << "- looking for" << numberOfSlashes << "slashes";
639  break;
640  }
641  }
642  if (pos >= 0) {
643  destFileName = path.mid(pos + 1);
644  }
645 
646  } else if ( fnu == KProtocolInfo::Name ) { // destination filename taken from UDS_NAME
647  destFileName = fileName;
648  } else { // from display name (with fallback to name)
649  const QString displayName = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
650  destFileName = displayName.isEmpty() ? fileName : displayName;
651  }
652 
653  // Here we _really_ have to add some filename to the dest.
654  // Otherwise, we end up with e.g. dest=..../Desktop/ itself.
655  // (This can happen when dropping a link to a webpage with no path)
656  if (destFileName.isEmpty()) {
657  destFileName = KIO::encodeFileName(info.uSource.prettyUrl());
658  }
659 
660  //kDebug(7007) << " adding destFileName=" << destFileName;
661  info.uDest.addPath(destFileName);
662  }
663  //kDebug(7007) << " uDest(2)=" << info.uDest;
664  //kDebug(7007) << " " << info.uSource << "->" << info.uDest;
665  if (info.linkDest.isEmpty() && isDir && m_mode != CopyJob::Link) { // Dir
666  dirs.append(info); // Directories
667  if (m_mode == CopyJob::Move) {
668  dirsToRemove.append(info.uSource);
669  }
670  } else {
671  files.append(info); // Files and any symlinks
672  }
673  }
674 }
675 
676 void CopyJobPrivate::skipSrc(bool isDir)
677 {
678  m_dest = m_globalDest;
679  destinationState = m_globalDestinationState;
680  skip(*m_currentStatSrc, isDir);
681  ++m_currentStatSrc;
682  statCurrentSrc();
683 }
684 
685 void CopyJobPrivate::statNextSrc()
686 {
687  /* Revert to the global destination, the one that applies to all source urls.
688  * Imagine you copy the items a b and c into /d, but /d/b exists so the user uses "Rename" to put it in /foo/b instead.
689  * d->m_dest is /foo/b for b, but we have to revert to /d for item c and following.
690  */
691  m_dest = m_globalDest;
692  destinationState = m_globalDestinationState;
693  ++m_currentStatSrc;
694  statCurrentSrc();
695 }
696 
697 void CopyJobPrivate::statCurrentSrc()
698 {
699  Q_Q(CopyJob);
700  if (m_currentStatSrc != m_srcList.constEnd()) {
701  m_currentSrcURL = (*m_currentStatSrc);
702  m_bURLDirty = true;
703  if (m_mode == CopyJob::Link) {
704  // Skip the "stating the source" stage, we don't need it for linking
705  m_currentDest = m_dest;
706  struct CopyInfo info;
707  info.permissions = -1;
708  info.mtime = (time_t) -1;
709  info.ctime = (time_t) -1;
710  info.size = (KIO::filesize_t)-1;
711  info.uSource = m_currentSrcURL;
712  info.uDest = m_currentDest;
713  // Append filename or dirname to destination URL, if allowed
714  if (destinationState == DEST_IS_DIR && !m_asMethod) {
715  if (
716  (m_currentSrcURL.protocol() == info.uDest.protocol()) &&
717  (m_currentSrcURL.host() == info.uDest.host()) &&
718  (m_currentSrcURL.port() == info.uDest.port()) &&
719  (m_currentSrcURL.user() == info.uDest.user()) &&
720  (m_currentSrcURL.pass() == info.uDest.pass()) ) {
721  // This is the case of creating a real symlink
722  info.uDest.addPath( m_currentSrcURL.fileName() );
723  } else {
724  // Different protocols, we'll create a .desktop file
725  // We have to change the extension anyway, so while we're at it,
726  // name the file like the URL
727  info.uDest.addPath(KIO::encodeFileName(m_currentSrcURL.prettyUrl()) + ".desktop");
728  }
729  }
730  files.append( info ); // Files and any symlinks
731  statNextSrc(); // we could use a loop instead of a recursive call :)
732  return;
733  }
734 
735  // Let's see if we can skip stat'ing, for the case where a directory view has the info already
736  const KFileItem cachedItem = KDirLister::cachedItemForUrl(m_currentSrcURL);
737  KIO::UDSEntry entry;
738  if (!cachedItem.isNull()) {
739  entry = cachedItem.entry();
740  if (destinationState != DEST_DOESNT_EXIST) { // only resolve src if we could resolve dest (#218719)
741  bool dummyIsLocal;
742  m_currentSrcURL = cachedItem.mostLocalUrl(dummyIsLocal); // #183585
743  }
744  }
745 
746  if (m_mode == CopyJob::Move && (
747  // Don't go renaming right away if we need a stat() to find out the destination filename
748  KProtocolManager::fileNameUsedForCopying(m_currentSrcURL) == KProtocolInfo::FromUrl ||
749  destinationState != DEST_IS_DIR || m_asMethod)
750  ) {
751  // If moving, before going for the full stat+[list+]copy+del thing, try to rename
752  // The logic is pretty similar to FileCopyJobPrivate::slotStart()
753  if ( (m_currentSrcURL.protocol() == m_dest.protocol()) &&
754  (m_currentSrcURL.host() == m_dest.host()) &&
755  (m_currentSrcURL.port() == m_dest.port()) &&
756  (m_currentSrcURL.user() == m_dest.user()) &&
757  (m_currentSrcURL.pass() == m_dest.pass()) )
758  {
759  startRenameJob( m_currentSrcURL );
760  return;
761  }
762  else if ( m_currentSrcURL.isLocalFile() && KProtocolManager::canRenameFromFile( m_dest ) )
763  {
764  startRenameJob( m_dest );
765  return;
766  }
767  else if ( m_dest.isLocalFile() && KProtocolManager::canRenameToFile( m_currentSrcURL ) )
768  {
769  startRenameJob( m_currentSrcURL );
770  return;
771  }
772  }
773 
774  // if the file system doesn't support deleting, we do not even stat
775  if (m_mode == CopyJob::Move && !KProtocolManager::supportsDeleting(m_currentSrcURL)) {
776  QPointer<CopyJob> that = q;
777  emit q->warning( q, buildErrorString(ERR_CANNOT_DELETE, m_currentSrcURL.prettyUrl()) );
778  if (that)
779  statNextSrc(); // we could use a loop instead of a recursive call :)
780  return;
781  }
782 
783  m_bOnlyRenames = false;
784 
785  // Testing for entry.count()>0 here is not good enough; KFileItem inserts
786  // entries for UDS_USER and UDS_GROUP even on initially empty UDSEntries (#192185)
787  if (entry.contains(KIO::UDSEntry::UDS_NAME)) {
788  kDebug(7007) << "fast path! found info about" << m_currentSrcURL << "in KDirLister";
789  // sourceStated(entry, m_currentSrcURL); // don't recurse, see #319747, use queued invokeMethod instead
790  QMetaObject::invokeMethod(q, "sourceStated", Qt::QueuedConnection, Q_ARG(KIO::UDSEntry, entry), Q_ARG(KUrl, m_currentSrcURL));
791  return;
792  }
793 
794  // Stat the next src url
795  Job * job = KIO::stat( m_currentSrcURL, StatJob::SourceSide, 2, KIO::HideProgressInfo );
796  //kDebug(7007) << "KIO::stat on" << m_currentSrcURL;
797  state = STATE_STATING;
798  q->addSubjob(job);
799  m_currentDestURL = m_dest;
800  m_bURLDirty = true;
801  }
802  else
803  {
804  // Finished the stat'ing phase
805  // First make sure that the totals were correctly emitted
806  state = STATE_STATING;
807  m_bURLDirty = true;
808  slotReport();
809 
810  kDebug(7007)<<"Stating finished. To copy:"<<m_totalSize<<", available:"<<m_freeSpace;
811  //TODO warn user beforehand if space is not enough
812 
813  if (!dirs.isEmpty())
814  emit q->aboutToCreate( q, dirs );
815  if (!files.isEmpty())
816  emit q->aboutToCreate( q, files );
817  // Check if we are copying a single file
818  m_bSingleFileCopy = ( files.count() == 1 && dirs.isEmpty() );
819  // Then start copying things
820  state = STATE_CREATING_DIRS;
821  createNextDir();
822  }
823 }
824 
825 void CopyJobPrivate::startRenameJob( const KUrl& slave_url )
826 {
827  Q_Q(CopyJob);
828 
829  // Silence KDirWatch notifications, otherwise performance is horrible
830  if (m_currentSrcURL.isLocalFile()) {
831  const QString parentDir = m_currentSrcURL.directory(KUrl::ObeyTrailingSlash);
832  if (!m_parentDirs.contains(parentDir)) {
833  KDirWatch::self()->stopDirScan(parentDir);
834  m_parentDirs.insert(parentDir);
835  }
836  }
837 
838  KUrl dest = m_dest;
839  // Append filename or dirname to destination URL, if allowed
840  if ( destinationState == DEST_IS_DIR && !m_asMethod )
841  dest.addPath( m_currentSrcURL.fileName() );
842  m_currentDestURL = dest;
843  kDebug(7007) << m_currentSrcURL << "->" << dest << "trying direct rename first";
844  state = STATE_RENAMING;
845 
846  struct CopyInfo info;
847  info.permissions = -1;
848  info.mtime = (time_t) -1;
849  info.ctime = (time_t) -1;
850  info.size = (KIO::filesize_t)-1;
851  info.uSource = m_currentSrcURL;
852  info.uDest = dest;
853  QList<CopyInfo> files;
854  files.append(info);
855  emit q->aboutToCreate( q, files );
856 
857  KIO_ARGS << m_currentSrcURL << dest << (qint8) false /*no overwrite*/;
858  SimpleJob * newJob = SimpleJobPrivate::newJobNoUi(slave_url, CMD_RENAME, packedArgs);
859  Scheduler::setJobPriority(newJob, 1);
860  q->addSubjob( newJob );
861  if ( m_currentSrcURL.directory() != dest.directory() ) // For the user, moving isn't renaming. Only renaming is.
862  m_bOnlyRenames = false;
863 }
864 
865 void CopyJobPrivate::startListing( const KUrl & src )
866 {
867  Q_Q(CopyJob);
868  state = STATE_LISTING;
869  m_bURLDirty = true;
870  ListJob * newjob = listRecursive(src, KIO::HideProgressInfo);
871  newjob->setUnrestricted(true);
872  q->connect(newjob, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
873  SLOT(slotEntries(KIO::Job*,KIO::UDSEntryList)));
874  q->connect(newjob, SIGNAL(subError(KIO::ListJob*,KIO::ListJob*)),
875  SLOT(slotSubError(KIO::ListJob*,KIO::ListJob*)));
876  q->addSubjob( newjob );
877 }
878 
879 void CopyJobPrivate::skip(const KUrl & sourceUrl, bool isDir)
880 {
881  KUrl dir = sourceUrl;
882  if (!isDir) {
883  // Skipping a file: make sure not to delete the parent dir (#208418)
884  dir.setPath(dir.directory());
885  }
886  while (dirsToRemove.removeAll(dir) > 0) {
887  // Do not rely on rmdir() on the parent directories aborting.
888  // Exclude the parent dirs explicitly.
889  dir.setPath(dir.directory());
890  }
891 }
892 
893 bool CopyJobPrivate::shouldOverwriteDir( const QString& path ) const
894 {
895  if ( m_bOverwriteAllDirs )
896  return true;
897  return m_overwriteList.contains(path);
898 }
899 
900 bool CopyJobPrivate::shouldOverwriteFile( const QString& path ) const
901 {
902  if ( m_bOverwriteAllFiles )
903  return true;
904  return m_overwriteList.contains(path);
905 }
906 
907 bool CopyJobPrivate::shouldSkip( const QString& path ) const
908 {
909  Q_FOREACH(const QString& skipPath, m_skipList) {
910  if ( path.startsWith(skipPath) )
911  return true;
912  }
913  return false;
914 }
915 
916 void CopyJobPrivate::slotResultCreatingDirs( KJob * job )
917 {
918  Q_Q(CopyJob);
919  // The dir we are trying to create:
920  QList<CopyInfo>::Iterator it = dirs.begin();
921  // Was there an error creating a dir ?
922  if ( job->error() )
923  {
924  m_conflictError = job->error();
925  if ( (m_conflictError == ERR_DIR_ALREADY_EXIST)
926  || (m_conflictError == ERR_FILE_ALREADY_EXIST) ) // can't happen?
927  {
928  KUrl oldURL = ((SimpleJob*)job)->url();
929  // Should we skip automatically ?
930  if ( m_bAutoSkipDirs ) {
931  // We don't want to copy files in this directory, so we put it on the skip list
932  m_skipList.append( oldURL.path( KUrl::AddTrailingSlash ) );
933  skip(oldURL, true);
934  dirs.erase( it ); // Move on to next dir
935  } else {
936  // Did the user choose to overwrite already?
937  const QString destDir = (*it).uDest.path();
938  if ( shouldOverwriteDir( destDir ) ) { // overwrite => just skip
939  emit q->copyingDone( q, (*it).uSource, (*it).uDest, (*it).mtime, true /* directory */, false /* renamed */ );
940  dirs.erase( it ); // Move on to next dir
941  } else {
942  if (m_bAutoRenameDirs) {
943  QString oldPath = (*it).uDest.path(KUrl::AddTrailingSlash);
944 
945  KUrl destDirectory((*it).uDest);
946  destDirectory.setPath(destDirectory.directory());
947  QString newName = KIO::RenameDialog::suggestName(destDirectory, (*it).uDest.fileName());
948 
949  KUrl newUrl((*it).uDest);
950  newUrl.setFileName(newName);
951 
952  emit q->renamed(q, (*it).uDest, newUrl); // for e.g. kpropsdlg
953 
954  // Change the current one and strip the trailing '/'
955  (*it).uDest.setPath(newUrl.path(KUrl::RemoveTrailingSlash));
956 
957  QString newPath = newUrl.path(KUrl::AddTrailingSlash); // With trailing slash
958  QList<CopyInfo>::Iterator renamedirit = it;
959  ++renamedirit;
960  // Change the name of subdirectories inside the directory
961  for(; renamedirit != dirs.end() ; ++renamedirit) {
962  QString path = (*renamedirit).uDest.path();
963  if (path.startsWith(oldPath)) {
964  QString n = path;
965  n.replace(0, oldPath.length(), newPath);
966  kDebug(7007) << "dirs list:" << (*renamedirit).uSource.path()
967  << "was going to be" << path
968  << ", changed into" << n;
969  (*renamedirit).uDest.setPath(n);
970  }
971  }
972  // Change filenames inside the directory
973  QList<CopyInfo>::Iterator renamefileit = files.begin();
974  for(; renamefileit != files.end() ; ++renamefileit) {
975  QString path = (*renamefileit).uDest.path();
976  if (path.startsWith(oldPath)) {
977  QString n = path;
978  n.replace(0, oldPath.length(), newPath);
979  kDebug(7007) << "files list:" << (*renamefileit).uSource.path()
980  << "was going to be" << path
981  << ", changed into" << n;
982  (*renamefileit).uDest.setPath(n);
983  }
984  }
985  if (!dirs.isEmpty()) {
986  emit q->aboutToCreate(q, dirs);
987  }
988  if (!files.isEmpty()) {
989  emit q->aboutToCreate(q, files);
990  }
991 
992  }
993  else {
994  if (!q->isInteractive()) {
995  q->Job::slotResult(job); // will set the error and emit result(this)
996  return;
997  }
998 
999  assert(((SimpleJob*)job)->url().url() == (*it).uDest.url());
1000  q->removeSubjob(job);
1001  assert (!q->hasSubjobs()); // We should have only one job at a time ...
1002 
1003  // We need to stat the existing dir, to get its last-modification time
1004  KUrl existingDest((*it).uDest);
1005  SimpleJob * newJob = KIO::stat(existingDest, StatJob::DestinationSide, 2, KIO::HideProgressInfo);
1006  Scheduler::setJobPriority(newJob, 1);
1007  kDebug(7007) << "KIO::stat for resolving conflict on " << existingDest;
1008  state = STATE_CONFLICT_CREATING_DIRS;
1009  q->addSubjob(newJob);
1010  return; // Don't move to next dir yet !
1011  }
1012  }
1013  }
1014  }
1015  else
1016  {
1017  // Severe error, abort
1018  q->Job::slotResult( job ); // will set the error and emit result(this)
1019  return;
1020  }
1021  }
1022  else // no error : remove from list, to move on to next dir
1023  {
1024  //this is required for the undo feature
1025  emit q->copyingDone( q, (*it).uSource, (*it).uDest, (*it).mtime, true, false );
1026  m_directoriesCopied.append( *it );
1027  dirs.erase( it );
1028  }
1029 
1030  m_processedDirs++;
1031  //emit processedAmount( this, KJob::Directories, m_processedDirs );
1032  q->removeSubjob( job );
1033  assert( !q->hasSubjobs() ); // We should have only one job at a time ...
1034  createNextDir();
1035 }
1036 
1037 void CopyJobPrivate::slotResultConflictCreatingDirs( KJob * job )
1038 {
1039  Q_Q(CopyJob);
1040  // We come here after a conflict has been detected and we've stated the existing dir
1041 
1042  // The dir we were trying to create:
1043  QList<CopyInfo>::Iterator it = dirs.begin();
1044 
1045  const UDSEntry entry = ((KIO::StatJob*)job)->statResult();
1046 
1047  // Its modification time:
1048  const time_t destmtime = (time_t) entry.numberValue( KIO::UDSEntry::UDS_MODIFICATION_TIME, -1 );
1049  const time_t destctime = (time_t) entry.numberValue( KIO::UDSEntry::UDS_CREATION_TIME, -1 );
1050 
1051  const KIO::filesize_t destsize = entry.numberValue( KIO::UDSEntry::UDS_SIZE );
1052  const QString linkDest = entry.stringValue( KIO::UDSEntry::UDS_LINK_DEST );
1053 
1054  q->removeSubjob( job );
1055  assert ( !q->hasSubjobs() ); // We should have only one job at a time ...
1056 
1057  // Always multi and skip (since there are files after that)
1058  RenameDialog_Mode mode = (RenameDialog_Mode)( M_MULTI | M_SKIP | M_ISDIR );
1059  // Overwrite only if the existing thing is a dir (no chance with a file)
1060  if ( m_conflictError == ERR_DIR_ALREADY_EXIST )
1061  {
1062  if( (*it).uSource == (*it).uDest ||
1063  ((*it).uSource.protocol() == (*it).uDest.protocol() &&
1064  (*it).uSource.path( KUrl::RemoveTrailingSlash ) == linkDest) )
1065  mode = (RenameDialog_Mode)( mode | M_OVERWRITE_ITSELF);
1066  else
1067  mode = (RenameDialog_Mode)( mode | M_OVERWRITE );
1068  }
1069 
1070  QString existingDest = (*it).uDest.path();
1071  QString newPath;
1072  if (m_reportTimer)
1073  m_reportTimer->stop();
1074  RenameDialog_Result r = q->ui()->askFileRename( q, i18n("Folder Already Exists"),
1075  (*it).uSource.url(),
1076  (*it).uDest.url(),
1077  mode, newPath,
1078  (*it).size, destsize,
1079  (*it).ctime, destctime,
1080  (*it).mtime, destmtime );
1081  if (m_reportTimer)
1082  m_reportTimer->start(REPORT_TIMEOUT);
1083  switch ( r ) {
1084  case R_CANCEL:
1085  q->setError( ERR_USER_CANCELED );
1086  q->emitResult();
1087  return;
1088  case R_AUTO_RENAME:
1089  m_bAutoRenameDirs = true;
1090  // fall through
1091  case R_RENAME:
1092  {
1093  QString oldPath = (*it).uDest.path( KUrl::AddTrailingSlash );
1094  KUrl newUrl( (*it).uDest );
1095  newUrl.setPath( newPath );
1096  emit q->renamed( q, (*it).uDest, newUrl ); // for e.g. kpropsdlg
1097 
1098  // Change the current one and strip the trailing '/'
1099  (*it).uDest.setPath( newUrl.path( KUrl::RemoveTrailingSlash ) );
1100  newPath = newUrl.path( KUrl::AddTrailingSlash ); // With trailing slash
1101  QList<CopyInfo>::Iterator renamedirit = it;
1102  ++renamedirit;
1103  // Change the name of subdirectories inside the directory
1104  for( ; renamedirit != dirs.end() ; ++renamedirit )
1105  {
1106  QString path = (*renamedirit).uDest.path();
1107  if ( path.startsWith( oldPath ) ) {
1108  QString n = path;
1109  n.replace( 0, oldPath.length(), newPath );
1110  kDebug(7007) << "dirs list:" << (*renamedirit).uSource.path()
1111  << "was going to be" << path
1112  << ", changed into" << n;
1113  (*renamedirit).uDest.setPath( n );
1114  }
1115  }
1116  // Change filenames inside the directory
1117  QList<CopyInfo>::Iterator renamefileit = files.begin();
1118  for( ; renamefileit != files.end() ; ++renamefileit )
1119  {
1120  QString path = (*renamefileit).uDest.path();
1121  if ( path.startsWith( oldPath ) ) {
1122  QString n = path;
1123  n.replace( 0, oldPath.length(), newPath );
1124  kDebug(7007) << "files list:" << (*renamefileit).uSource.path()
1125  << "was going to be" << path
1126  << ", changed into" << n;
1127  (*renamefileit).uDest.setPath( n );
1128  }
1129  }
1130  if (!dirs.isEmpty())
1131  emit q->aboutToCreate( q, dirs );
1132  if (!files.isEmpty())
1133  emit q->aboutToCreate( q, files );
1134  }
1135  break;
1136  case R_AUTO_SKIP:
1137  m_bAutoSkipDirs = true;
1138  // fall through
1139  case R_SKIP:
1140  m_skipList.append( existingDest );
1141  skip((*it).uSource, true);
1142  // Move on to next dir
1143  dirs.erase( it );
1144  m_processedDirs++;
1145  break;
1146  case R_OVERWRITE:
1147  m_overwriteList.insert( existingDest );
1148  emit q->copyingDone( q, (*it).uSource, (*it).uDest, (*it).mtime, true /* directory */, false /* renamed */ );
1149  // Move on to next dir
1150  dirs.erase( it );
1151  m_processedDirs++;
1152  break;
1153  case R_OVERWRITE_ALL:
1154  m_bOverwriteAllDirs = true;
1155  emit q->copyingDone( q, (*it).uSource, (*it).uDest, (*it).mtime, true /* directory */, false /* renamed */ );
1156  // Move on to next dir
1157  dirs.erase( it );
1158  m_processedDirs++;
1159  break;
1160  default:
1161  assert( 0 );
1162  }
1163  state = STATE_CREATING_DIRS;
1164  //emit processedAmount( this, KJob::Directories, m_processedDirs );
1165  createNextDir();
1166 }
1167 
1168 void CopyJobPrivate::createNextDir()
1169 {
1170  Q_Q(CopyJob);
1171  KUrl udir;
1172  if ( !dirs.isEmpty() )
1173  {
1174  // Take first dir to create out of list
1175  QList<CopyInfo>::Iterator it = dirs.begin();
1176  // Is this URL on the skip list or the overwrite list ?
1177  while( it != dirs.end() && udir.isEmpty() )
1178  {
1179  const QString dir = (*it).uDest.path();
1180  if ( shouldSkip( dir ) ) {
1181  dirs.erase( it );
1182  it = dirs.begin();
1183  } else
1184  udir = (*it).uDest;
1185  }
1186  }
1187  if ( !udir.isEmpty() ) // any dir to create, finally ?
1188  {
1189  // Create the directory - with default permissions so that we can put files into it
1190  // TODO : change permissions once all is finished; but for stuff coming from CDROM it sucks...
1191  KIO::SimpleJob *newjob = KIO::mkdir( udir, -1 );
1192  Scheduler::setJobPriority(newjob, 1);
1193  if (shouldOverwriteFile(udir.path())) { // if we are overwriting an existing file or symlink
1194  newjob->addMetaData("overwrite", "true");
1195  }
1196 
1197  m_currentDestURL = udir;
1198  m_bURLDirty = true;
1199 
1200  q->addSubjob(newjob);
1201  return;
1202  }
1203  else // we have finished creating dirs
1204  {
1205  q->setProcessedAmount( KJob::Directories, m_processedDirs ); // make sure final number appears
1206 
1207  if (m_mode == CopyJob::Move) {
1208  // Now we know which dirs hold the files we're going to delete.
1209  // To speed things up and prevent double-notification, we disable KDirWatch
1210  // on those dirs temporarily (using KDirWatch::self, that's the instanced
1211  // used by e.g. kdirlister).
1212  for ( QSet<QString>::const_iterator it = m_parentDirs.constBegin() ; it != m_parentDirs.constEnd() ; ++it )
1213  KDirWatch::self()->stopDirScan( *it );
1214  }
1215 
1216  state = STATE_COPYING_FILES;
1217  m_processedFiles++; // Ralf wants it to start at 1, not 0
1218  copyNextFile();
1219  }
1220 }
1221 
1222 void CopyJobPrivate::slotResultCopyingFiles( KJob * job )
1223 {
1224  Q_Q(CopyJob);
1225  // The file we were trying to copy:
1226  QList<CopyInfo>::Iterator it = files.begin();
1227  if ( job->error() )
1228  {
1229  // Should we skip automatically ?
1230  if ( m_bAutoSkipFiles )
1231  {
1232  skip((*it).uSource, false);
1233  m_fileProcessedSize = (*it).size;
1234  files.erase( it ); // Move on to next file
1235  }
1236  else
1237  {
1238  m_conflictError = job->error(); // save for later
1239  // Existing dest ?
1240  if ( ( m_conflictError == ERR_FILE_ALREADY_EXIST )
1241  || ( m_conflictError == ERR_DIR_ALREADY_EXIST )
1242  || ( m_conflictError == ERR_IDENTICAL_FILES ) )
1243  {
1244  if (m_bAutoRenameFiles) {
1245  KUrl destDirectory((*it).uDest);
1246  destDirectory.setPath(destDirectory.directory());
1247  const QString newName = KIO::RenameDialog::suggestName(destDirectory, (*it).uDest.fileName());
1248 
1249  KUrl newUrl((*it).uDest);
1250  newUrl.setFileName(newName);
1251 
1252  emit q->renamed(q, (*it).uDest, newUrl); // for e.g. kpropsdlg
1253  (*it).uDest = newUrl;
1254 
1255  QList<CopyInfo> files;
1256  files.append(*it);
1257  emit q->aboutToCreate(q, files);
1258  }
1259  else {
1260  if ( !q->isInteractive() ) {
1261  q->Job::slotResult( job ); // will set the error and emit result(this)
1262  return;
1263  }
1264 
1265  q->removeSubjob(job);
1266  assert (!q->hasSubjobs());
1267  // We need to stat the existing file, to get its last-modification time
1268  KUrl existingFile((*it).uDest);
1269  SimpleJob * newJob = KIO::stat(existingFile, StatJob::DestinationSide, 2, KIO::HideProgressInfo);
1270  Scheduler::setJobPriority(newJob, 1);
1271  kDebug(7007) << "KIO::stat for resolving conflict on " << existingFile;
1272  state = STATE_CONFLICT_COPYING_FILES;
1273  q->addSubjob(newJob);
1274  return; // Don't move to next file yet !
1275  }
1276  }
1277  else
1278  {
1279  if ( m_bCurrentOperationIsLink && qobject_cast<KIO::DeleteJob*>( job ) )
1280  {
1281  // Very special case, see a few lines below
1282  // We are deleting the source of a symlink we successfully moved... ignore error
1283  m_fileProcessedSize = (*it).size;
1284  files.erase( it );
1285  } else {
1286  if ( !q->isInteractive() ) {
1287  q->Job::slotResult( job ); // will set the error and emit result(this)
1288  return;
1289  }
1290 
1291  // Go directly to the conflict resolution, there is nothing to stat
1292  slotResultConflictCopyingFiles( job );
1293  return;
1294  }
1295  }
1296  }
1297  } else // no error
1298  {
1299  // Special case for moving links. That operation needs two jobs, unlike others.
1300  if ( m_bCurrentOperationIsLink && m_mode == CopyJob::Move
1301  && !qobject_cast<KIO::DeleteJob *>( job ) // Deleting source not already done
1302  )
1303  {
1304  q->removeSubjob( job );
1305  assert ( !q->hasSubjobs() );
1306  // The only problem with this trick is that the error handling for this del operation
1307  // is not going to be right... see 'Very special case' above.
1308  KIO::Job * newjob = KIO::del( (*it).uSource, HideProgressInfo );
1309  q->addSubjob( newjob );
1310  return; // Don't move to next file yet !
1311  }
1312 
1313  if ( m_bCurrentOperationIsLink )
1314  {
1315  QString target = ( m_mode == CopyJob::Link ? (*it).uSource.path() : (*it).linkDest );
1316  //required for the undo feature
1317  emit q->copyingLinkDone( q, (*it).uSource, target, (*it).uDest );
1318  }
1319  else {
1320  //required for the undo feature
1321  emit q->copyingDone( q, (*it).uSource, (*it).uDest, (*it).mtime, false, false );
1322  if (m_mode == CopyJob::Move)
1323  {
1324  org::kde::KDirNotify::emitFileMoved( (*it).uSource.url(), (*it).uDest.url() );
1325  }
1326  m_successSrcList.append((*it).uSource);
1327  if (m_freeSpace != (KIO::filesize_t)-1 && (*it).size != (KIO::filesize_t)-1) {
1328  m_freeSpace -= (*it).size;
1329  }
1330 
1331  }
1332  // remove from list, to move on to next file
1333  files.erase( it );
1334  }
1335  m_processedFiles++;
1336 
1337  // clear processed size for last file and add it to overall processed size
1338  m_processedSize += m_fileProcessedSize;
1339  m_fileProcessedSize = 0;
1340 
1341  //kDebug(7007) << files.count() << "files remaining";
1342 
1343  // Merge metadata from subjob
1344  KIO::Job* kiojob = dynamic_cast<KIO::Job*>(job);
1345  Q_ASSERT(kiojob);
1346  m_incomingMetaData += kiojob->metaData();
1347  q->removeSubjob( job );
1348  assert( !q->hasSubjobs() ); // We should have only one job at a time ...
1349  copyNextFile();
1350 }
1351 
1352 void CopyJobPrivate::slotResultConflictCopyingFiles( KJob * job )
1353 {
1354  Q_Q(CopyJob);
1355  // We come here after a conflict has been detected and we've stated the existing file
1356  // The file we were trying to create:
1357  QList<CopyInfo>::Iterator it = files.begin();
1358 
1359  RenameDialog_Result res;
1360  QString newPath;
1361 
1362  if (m_reportTimer)
1363  m_reportTimer->stop();
1364 
1365  if ( ( m_conflictError == ERR_FILE_ALREADY_EXIST )
1366  || ( m_conflictError == ERR_DIR_ALREADY_EXIST )
1367  || ( m_conflictError == ERR_IDENTICAL_FILES ) )
1368  {
1369  // Its modification time:
1370  const UDSEntry entry = ((KIO::StatJob*)job)->statResult();
1371 
1372  const time_t destmtime = (time_t) entry.numberValue( KIO::UDSEntry::UDS_MODIFICATION_TIME, -1 );
1373  const time_t destctime = (time_t) entry.numberValue( KIO::UDSEntry::UDS_CREATION_TIME, -1 );
1374  const KIO::filesize_t destsize = entry.numberValue( KIO::UDSEntry::UDS_SIZE );
1375  const QString linkDest = entry.stringValue( KIO::UDSEntry::UDS_LINK_DEST );
1376 
1377  // Offer overwrite only if the existing thing is a file
1378  // If src==dest, use "overwrite-itself"
1379  RenameDialog_Mode mode;
1380  bool isDir = true;
1381 
1382  if( m_conflictError == ERR_DIR_ALREADY_EXIST )
1383  mode = M_ISDIR;
1384  else
1385  {
1386  if ( (*it).uSource == (*it).uDest ||
1387  ((*it).uSource.protocol() == (*it).uDest.protocol() &&
1388  (*it).uSource.path( KUrl::RemoveTrailingSlash ) == linkDest) )
1389  mode = M_OVERWRITE_ITSELF;
1390  else
1391  mode = M_OVERWRITE;
1392  isDir = false;
1393  }
1394 
1395  if ( !m_bSingleFileCopy )
1396  mode = (RenameDialog_Mode) ( mode | M_MULTI | M_SKIP );
1397 
1398  res = q->ui()->askFileRename( q, !isDir ?
1399  i18n("File Already Exists") : i18n("Already Exists as Folder"),
1400  (*it).uSource.url(),
1401  (*it).uDest.url(),
1402  mode, newPath,
1403  (*it).size, destsize,
1404  (*it).ctime, destctime,
1405  (*it).mtime, destmtime );
1406 
1407  }
1408  else
1409  {
1410  if ( job->error() == ERR_USER_CANCELED )
1411  res = R_CANCEL;
1412  else if ( !q->isInteractive() ) {
1413  q->Job::slotResult( job ); // will set the error and emit result(this)
1414  return;
1415  }
1416  else
1417  {
1418  SkipDialog_Result skipResult = q->ui()->askSkip( q, files.count() > 1,
1419  job->errorString() );
1420 
1421  // Convert the return code from SkipDialog into a RenameDialog code
1422  res = ( skipResult == S_SKIP ) ? R_SKIP :
1423  ( skipResult == S_AUTO_SKIP ) ? R_AUTO_SKIP :
1424  R_CANCEL;
1425  }
1426  }
1427 
1428  if (m_reportTimer)
1429  m_reportTimer->start(REPORT_TIMEOUT);
1430 
1431  q->removeSubjob( job );
1432  assert ( !q->hasSubjobs() );
1433  switch ( res ) {
1434  case R_CANCEL:
1435  q->setError( ERR_USER_CANCELED );
1436  q->emitResult();
1437  return;
1438  case R_AUTO_RENAME:
1439  m_bAutoRenameFiles = true;
1440  // fall through
1441  case R_RENAME:
1442  {
1443  KUrl newUrl( (*it).uDest );
1444  newUrl.setPath( newPath );
1445  emit q->renamed( q, (*it).uDest, newUrl ); // for e.g. kpropsdlg
1446  (*it).uDest = newUrl;
1447 
1448  QList<CopyInfo> files;
1449  files.append(*it);
1450  emit q->aboutToCreate( q, files );
1451  }
1452  break;
1453  case R_AUTO_SKIP:
1454  m_bAutoSkipFiles = true;
1455  // fall through
1456  case R_SKIP:
1457  // Move on to next file
1458  skip((*it).uSource, false);
1459  m_processedSize += (*it).size;
1460  files.erase( it );
1461  m_processedFiles++;
1462  break;
1463  case R_OVERWRITE_ALL:
1464  m_bOverwriteAllFiles = true;
1465  break;
1466  case R_OVERWRITE:
1467  // Add to overwrite list, so that copyNextFile knows to overwrite
1468  m_overwriteList.insert( (*it).uDest.path() );
1469  break;
1470  default:
1471  assert( 0 );
1472  }
1473  state = STATE_COPYING_FILES;
1474  copyNextFile();
1475 }
1476 
1477 KIO::Job* CopyJobPrivate::linkNextFile( const KUrl& uSource, const KUrl& uDest, JobFlags flags )
1478 {
1479  //kDebug(7007) << "Linking";
1480  if (
1481  (uSource.protocol() == uDest.protocol()) &&
1482  (uSource.host() == uDest.host()) &&
1483  (uSource.port() == uDest.port()) &&
1484  (uSource.user() == uDest.user()) &&
1485  (uSource.pass() == uDest.pass()) )
1486  {
1487  // This is the case of creating a real symlink
1488  KIO::SimpleJob *newJob = KIO::symlink( uSource.path(), uDest, flags|HideProgressInfo /*no GUI*/ );
1489  Scheduler::setJobPriority(newJob, 1);
1490  //kDebug(7007) << "Linking target=" << uSource.path() << "link=" << uDest;
1491  //emit linking( this, uSource.path(), uDest );
1492  m_bCurrentOperationIsLink = true;
1493  m_currentSrcURL=uSource;
1494  m_currentDestURL=uDest;
1495  m_bURLDirty = true;
1496  //Observer::self()->slotCopying( this, uSource, uDest ); // should be slotLinking perhaps
1497  return newJob;
1498  } else {
1499  Q_Q(CopyJob);
1500  //kDebug(7007) << "Linking URL=" << uSource << "link=" << uDest;
1501  if ( uDest.isLocalFile() ) {
1502  // if the source is a devices url, handle it a littlebit special
1503 
1504  QString path = uDest.toLocalFile();
1505  //kDebug(7007) << "path=" << path;
1506  QFile f( path );
1507  if ( f.open( QIODevice::ReadWrite ) )
1508  {
1509  f.close();
1510  KDesktopFile desktopFile( path );
1511  KConfigGroup config = desktopFile.desktopGroup();
1512  KUrl url = uSource;
1513  url.setPass( "" );
1514  config.writePathEntry( "URL", url.url() );
1515  config.writeEntry( "Name", url.url() );
1516  config.writeEntry( "Type", QString::fromLatin1("Link") );
1517  QString protocol = uSource.protocol();
1518  if ( protocol == QLatin1String("ftp") )
1519  config.writeEntry( "Icon", QString::fromLatin1("folder-remote") );
1520  else if ( protocol == QLatin1String("http") )
1521  config.writeEntry( "Icon", QString::fromLatin1("text-html") );
1522  else if ( protocol == QLatin1String("info") )
1523  config.writeEntry( "Icon", QString::fromLatin1("text-x-texinfo") );
1524  else if ( protocol == QLatin1String("mailto") ) // sven:
1525  config.writeEntry( "Icon", QString::fromLatin1("internet-mail") ); // added mailto: support
1526  else
1527  config.writeEntry( "Icon", QString::fromLatin1("unknown") );
1528  config.sync();
1529  files.erase( files.begin() ); // done with this one, move on
1530  m_processedFiles++;
1531  //emit processedAmount( this, KJob::Files, m_processedFiles );
1532  copyNextFile();
1533  return 0;
1534  }
1535  else
1536  {
1537  kDebug(7007) << "ERR_CANNOT_OPEN_FOR_WRITING";
1538  q->setError( ERR_CANNOT_OPEN_FOR_WRITING );
1539  q->setErrorText( uDest.toLocalFile() );
1540  q->emitResult();
1541  return 0;
1542  }
1543  } else {
1544  // Todo: not show "link" on remote dirs if the src urls are not from the same protocol+host+...
1545  q->setError( ERR_CANNOT_SYMLINK );
1546  q->setErrorText( uDest.prettyUrl() );
1547  q->emitResult();
1548  return 0;
1549  }
1550  }
1551 }
1552 
1553 void CopyJobPrivate::copyNextFile()
1554 {
1555  Q_Q(CopyJob);
1556  bool bCopyFile = false;
1557  //kDebug(7007);
1558  // Take the first file in the list
1559  QList<CopyInfo>::Iterator it = files.begin();
1560  // Is this URL on the skip list ?
1561  while (it != files.end() && !bCopyFile)
1562  {
1563  const QString destFile = (*it).uDest.path();
1564  bCopyFile = !shouldSkip( destFile );
1565  if ( !bCopyFile ) {
1566  files.erase( it );
1567  it = files.begin();
1568  }
1569  }
1570 
1571  if (bCopyFile) // any file to create, finally ?
1572  {
1573  //kDebug()<<"preparing to copy"<<(*it).uSource<<(*it).size<<m_freeSpace;
1574  if (m_freeSpace != (KIO::filesize_t)-1 && (*it).size != (KIO::filesize_t)-1) {
1575  if (m_freeSpace < (*it).size) {
1576  q->setError( ERR_DISK_FULL );
1577  q->emitResult();
1578  return;
1579  }
1580  //TODO check if dst mount is msdos and (*it).size exceeds it's limits
1581  }
1582 
1583  const KUrl& uSource = (*it).uSource;
1584  const KUrl& uDest = (*it).uDest;
1585  // Do we set overwrite ?
1586  bool bOverwrite;
1587  const QString destFile = uDest.path();
1588  // kDebug(7007) << "copying" << destFile;
1589  if ( uDest == uSource )
1590  bOverwrite = false;
1591  else
1592  bOverwrite = shouldOverwriteFile( destFile );
1593 
1594  m_bCurrentOperationIsLink = false;
1595  KIO::Job * newjob = 0;
1596  if ( m_mode == CopyJob::Link ) {
1597  // User requested that a symlink be made
1598  const JobFlags flags = bOverwrite ? Overwrite : DefaultFlags;
1599  newjob = linkNextFile(uSource, uDest, flags);
1600  if (!newjob)
1601  return;
1602  } else if ( !(*it).linkDest.isEmpty() &&
1603  (uSource.protocol() == uDest.protocol()) &&
1604  (uSource.host() == uDest.host()) &&
1605  (uSource.port() == uDest.port()) &&
1606  (uSource.user() == uDest.user()) &&
1607  (uSource.pass() == uDest.pass()))
1608  // Copying a symlink - only on the same protocol/host/etc. (#5601, downloading an FTP file through its link),
1609  {
1610  const JobFlags flags = bOverwrite ? Overwrite : DefaultFlags;
1611  KIO::SimpleJob *newJob = KIO::symlink( (*it).linkDest, uDest, flags | HideProgressInfo /*no GUI*/ );
1612  Scheduler::setJobPriority(newJob, 1);
1613  newjob = newJob;
1614  //kDebug(7007) << "Linking target=" << (*it).linkDest << "link=" << uDest;
1615  m_currentSrcURL = KUrl( (*it).linkDest );
1616  m_currentDestURL = uDest;
1617  m_bURLDirty = true;
1618  //emit linking( this, (*it).linkDest, uDest );
1619  //Observer::self()->slotCopying( this, m_currentSrcURL, uDest ); // should be slotLinking perhaps
1620  m_bCurrentOperationIsLink = true;
1621  // NOTE: if we are moving stuff, the deletion of the source will be done in slotResultCopyingFiles
1622  } else if (m_mode == CopyJob::Move) // Moving a file
1623  {
1624  JobFlags flags = bOverwrite ? Overwrite : DefaultFlags;
1625  KIO::FileCopyJob * moveJob = KIO::file_move( uSource, uDest, (*it).permissions, flags | HideProgressInfo/*no GUI*/ );
1626  moveJob->setSourceSize( (*it).size );
1627  if ((*it).mtime != -1) {
1628  moveJob->setModificationTime( QDateTime::fromTime_t( (*it).mtime ) ); // #55804
1629  }
1630  newjob = moveJob;
1631  //kDebug(7007) << "Moving" << uSource << "to" << uDest;
1632  //emit moving( this, uSource, uDest );
1633  m_currentSrcURL=uSource;
1634  m_currentDestURL=uDest;
1635  m_bURLDirty = true;
1636  //Observer::self()->slotMoving( this, uSource, uDest );
1637  }
1638  else // Copying a file
1639  {
1640  // If source isn't local and target is local, we ignore the original permissions
1641  // Otherwise, files downloaded from HTTP end up with -r--r--r--
1642  bool remoteSource = !KProtocolManager::supportsListing(uSource);
1643  int permissions = (*it).permissions;
1644  if ( m_defaultPermissions || ( remoteSource && uDest.isLocalFile() ) )
1645  permissions = -1;
1646  JobFlags flags = bOverwrite ? Overwrite : DefaultFlags;
1647  KIO::FileCopyJob * copyJob = KIO::file_copy( uSource, uDest, permissions, flags | HideProgressInfo/*no GUI*/ );
1648  copyJob->setParentJob( q ); // in case of rename dialog
1649  copyJob->setSourceSize( (*it).size );
1650  if ((*it).mtime != -1) {
1651  copyJob->setModificationTime( QDateTime::fromTime_t( (*it).mtime ) );
1652  }
1653  newjob = copyJob;
1654  //kDebug(7007) << "Copying" << uSource << "to" << uDest;
1655  m_currentSrcURL=uSource;
1656  m_currentDestURL=uDest;
1657  m_bURLDirty = true;
1658  }
1659  q->addSubjob(newjob);
1660  q->connect( newjob, SIGNAL(processedSize(KJob*,qulonglong)),
1661  SLOT(slotProcessedSize(KJob*,qulonglong)) );
1662  q->connect( newjob, SIGNAL(totalSize(KJob*,qulonglong)),
1663  SLOT(slotTotalSize(KJob*,qulonglong)) );
1664  }
1665  else
1666  {
1667  // We're done
1668  //kDebug(7007) << "copyNextFile finished";
1669  deleteNextDir();
1670  }
1671 }
1672 
1673 void CopyJobPrivate::deleteNextDir()
1674 {
1675  Q_Q(CopyJob);
1676  if ( m_mode == CopyJob::Move && !dirsToRemove.isEmpty() ) // some dirs to delete ?
1677  {
1678  state = STATE_DELETING_DIRS;
1679  m_bURLDirty = true;
1680  // Take first dir to delete out of list - last ones first !
1681  KUrl::List::Iterator it = --dirsToRemove.end();
1682  SimpleJob *job = KIO::rmdir( *it );
1683  Scheduler::setJobPriority(job, 1);
1684  dirsToRemove.erase(it);
1685  q->addSubjob( job );
1686  }
1687  else
1688  {
1689  // This step is done, move on
1690  state = STATE_SETTING_DIR_ATTRIBUTES;
1691  m_directoriesCopiedIterator = m_directoriesCopied.constBegin();
1692  setNextDirAttribute();
1693  }
1694 }
1695 
1696 void CopyJobPrivate::setNextDirAttribute()
1697 {
1698  Q_Q(CopyJob);
1699  while (m_directoriesCopiedIterator != m_directoriesCopied.constEnd() &&
1700  (*m_directoriesCopiedIterator).mtime == -1) {
1701  ++m_directoriesCopiedIterator;
1702  }
1703  if ( m_directoriesCopiedIterator != m_directoriesCopied.constEnd() ) {
1704  const KUrl url = (*m_directoriesCopiedIterator).uDest;
1705  const time_t mtime = (*m_directoriesCopiedIterator).mtime;
1706  const QDateTime dt = QDateTime::fromTime_t(mtime);
1707  ++m_directoriesCopiedIterator;
1708 
1709  KIO::SimpleJob *job = KIO::setModificationTime( url, dt );
1710  Scheduler::setJobPriority(job, 1);
1711  q->addSubjob( job );
1712 
1713 
1714 #if 0 // ifdef Q_OS_UNIX
1715  // TODO: can be removed now. Or reintroduced as a fast path for local files
1716  // if launching even more jobs as done above is a performance problem.
1717  //
1718  QLinkedList<CopyInfo>::const_iterator it = m_directoriesCopied.constBegin();
1719  for ( ; it != m_directoriesCopied.constEnd() ; ++it ) {
1720  const KUrl& url = (*it).uDest;
1721  if ( url.isLocalFile() && (*it).mtime != (time_t)-1 ) {
1722  KDE_struct_stat statbuf;
1723  if (KDE::lstat(url.path(), &statbuf) == 0) {
1724  struct utimbuf utbuf;
1725  utbuf.actime = statbuf.st_atime; // access time, unchanged
1726  utbuf.modtime = (*it).mtime; // modification time
1727  utime( path, &utbuf );
1728  }
1729 
1730  }
1731  }
1732  m_directoriesCopied.clear();
1733  // but then we need to jump to the else part below. Maybe with a recursive call?
1734 #endif
1735  } else {
1736  if (m_reportTimer)
1737  m_reportTimer->stop();
1738  --m_processedFiles; // undo the "start at 1" hack
1739  slotReport(); // display final numbers, important if progress dialog stays up
1740 
1741  q->emitResult();
1742  }
1743 }
1744 
1745 void CopyJob::emitResult()
1746 {
1747  Q_D(CopyJob);
1748  // Before we go, tell the world about the changes that were made.
1749  // Even if some error made us abort midway, we might still have done
1750  // part of the job so we better update the views! (#118583)
1751  if (!d->m_bOnlyRenames) {
1752  // If only renaming happened, KDirNotify::FileRenamed was emitted by the rename jobs
1753  KUrl url(d->m_globalDest);
1754  if (d->m_globalDestinationState != DEST_IS_DIR || d->m_asMethod)
1755  url.setPath(url.directory());
1756  //kDebug(7007) << "KDirNotify'ing FilesAdded" << url;
1757  org::kde::KDirNotify::emitFilesAdded( url.url() );
1758 
1759  if (d->m_mode == CopyJob::Move && !d->m_successSrcList.isEmpty()) {
1760  kDebug(7007) << "KDirNotify'ing FilesRemoved" << d->m_successSrcList.toStringList();
1761  org::kde::KDirNotify::emitFilesRemoved(d->m_successSrcList.toStringList());
1762  }
1763  }
1764 
1765  // Re-enable watching on the dirs that held the deleted/moved files
1766  if (d->m_mode == CopyJob::Move) {
1767  for (QSet<QString>::const_iterator it = d->m_parentDirs.constBegin() ; it != d->m_parentDirs.constEnd() ; ++it)
1768  KDirWatch::self()->restartDirScan( *it );
1769  }
1770  Job::emitResult();
1771 }
1772 
1773 void CopyJobPrivate::slotProcessedSize( KJob*, qulonglong data_size )
1774 {
1775  Q_Q(CopyJob);
1776  //kDebug(7007) << data_size;
1777  m_fileProcessedSize = data_size;
1778  q->setProcessedAmount(KJob::Bytes, m_processedSize + m_fileProcessedSize);
1779 
1780  if ( m_processedSize + m_fileProcessedSize > m_totalSize )
1781  {
1782  // Example: download any attachment from bugs.kde.org
1783  m_totalSize = m_processedSize + m_fileProcessedSize;
1784  //kDebug(7007) << "Adjusting m_totalSize to" << m_totalSize;
1785  q->setTotalAmount(KJob::Bytes, m_totalSize); // safety
1786  }
1787  //kDebug(7007) << "emit processedSize" << (unsigned long) (m_processedSize + m_fileProcessedSize);
1788  q->setProcessedAmount(KJob::Bytes, m_processedSize + m_fileProcessedSize);
1789 }
1790 
1791 void CopyJobPrivate::slotTotalSize( KJob*, qulonglong size )
1792 {
1793  Q_Q(CopyJob);
1794  //kDebug(7007) << size;
1795  // Special case for copying a single file
1796  // This is because some protocols don't implement stat properly
1797  // (e.g. HTTP), and don't give us a size in some cases (redirection)
1798  // so we'd rather rely on the size given for the transfer
1799  if ( m_bSingleFileCopy && size != m_totalSize)
1800  {
1801  //kDebug(7007) << "slotTotalSize: updating totalsize to" << size;
1802  m_totalSize = size;
1803  q->setTotalAmount(KJob::Bytes, size);
1804  }
1805 }
1806 
1807 void CopyJobPrivate::slotResultDeletingDirs( KJob * job )
1808 {
1809  Q_Q(CopyJob);
1810  if (job->error()) {
1811  // Couldn't remove directory. Well, perhaps it's not empty
1812  // because the user pressed Skip for a given file in it.
1813  // Let's not display "Could not remove dir ..." for each of those dir !
1814  } else {
1815  m_successSrcList.append(static_cast<KIO::SimpleJob*>(job)->url());
1816  }
1817  q->removeSubjob( job );
1818  assert( !q->hasSubjobs() );
1819  deleteNextDir();
1820 }
1821 
1822 void CopyJobPrivate::slotResultSettingDirAttributes( KJob * job )
1823 {
1824  Q_Q(CopyJob);
1825  if (job->error())
1826  {
1827  // Couldn't set directory attributes. Ignore the error, it can happen
1828  // with inferior file systems like VFAT.
1829  // Let's not display warnings for each dir like "cp -a" does.
1830  }
1831  q->removeSubjob( job );
1832  assert( !q->hasSubjobs() );
1833  setNextDirAttribute();
1834 }
1835 
1836 // We were trying to do a direct renaming, before even stat'ing
1837 void CopyJobPrivate::slotResultRenaming( KJob* job )
1838 {
1839  Q_Q(CopyJob);
1840  int err = job->error();
1841  const QString errText = job->errorText();
1842  // Merge metadata from subjob
1843  KIO::Job* kiojob = dynamic_cast<KIO::Job*>(job);
1844  Q_ASSERT(kiojob);
1845  m_incomingMetaData += kiojob->metaData();
1846  q->removeSubjob( job );
1847  assert ( !q->hasSubjobs() );
1848  // Determine dest again
1849  KUrl dest = m_dest;
1850  if ( destinationState == DEST_IS_DIR && !m_asMethod )
1851  dest.addPath( m_currentSrcURL.fileName() );
1852  if ( err )
1853  {
1854  // Direct renaming didn't work. Try renaming to a temp name,
1855  // this can help e.g. when renaming 'a' to 'A' on a VFAT partition.
1856  // In that case it's the _same_ dir, we don't want to copy+del (data loss!)
1857  if ( m_currentSrcURL.isLocalFile() && m_currentSrcURL.url(KUrl::RemoveTrailingSlash) != dest.url(KUrl::RemoveTrailingSlash) &&
1858  m_currentSrcURL.url(KUrl::RemoveTrailingSlash).toLower() == dest.url(KUrl::RemoveTrailingSlash).toLower() &&
1859  ( err == ERR_FILE_ALREADY_EXIST ||
1860  err == ERR_DIR_ALREADY_EXIST ||
1861  err == ERR_IDENTICAL_FILES ) )
1862  {
1863  kDebug(7007) << "Couldn't rename directly, dest already exists. Detected special case of lower/uppercase renaming in same dir, try with 2 rename calls";
1864  const QString _src( m_currentSrcURL.toLocalFile() );
1865  const QString _dest( dest.toLocalFile() );
1866  const QString _tmpPrefix = m_currentSrcURL.directory(KUrl::ObeyTrailingSlash|KUrl::AppendTrailingSlash);
1867  KTemporaryFile tmpFile;
1868  tmpFile.setPrefix(_tmpPrefix);
1869  const bool openOk = tmpFile.open();
1870  if (!openOk) {
1871  kWarning(7007) << "Couldn't open temp file in" << _tmpPrefix;
1872  } else {
1873  const QString _tmp( tmpFile.fileName() );
1874  tmpFile.close();
1875  tmpFile.remove();
1876  kDebug(7007) << "KTemporaryFile using" << _tmp << "as intermediary";
1877  if (KDE::rename( _src, _tmp ) == 0) {
1878  //kDebug(7007) << "Renaming" << _src << "to" << _tmp << "succeeded";
1879  if (!QFile::exists( _dest ) && KDE::rename(_tmp, _dest) == 0) {
1880  err = 0;
1881  org::kde::KDirNotify::emitFileRenamed(m_currentSrcURL.url(), dest.url());
1882  } else {
1883  kDebug(7007) << "Didn't manage to rename" << _tmp << "to" << _dest << ", reverting";
1884  // Revert back to original name!
1885  if (KDE::rename( _tmp, _src ) != 0) {
1886  kError(7007) << "Couldn't rename" << _tmp << "back to" << _src << '!';
1887  // Severe error, abort
1888  q->Job::slotResult(job); // will set the error and emit result(this)
1889  return;
1890  }
1891  }
1892  } else {
1893  kDebug(7007) << "mv" << _src << _tmp << "failed:" << strerror(errno);
1894  }
1895  }
1896  }
1897  }
1898  if ( err )
1899  {
1900  // This code is similar to CopyJobPrivate::slotResultConflictCopyingFiles
1901  // but here it's about the base src url being moved/renamed
1902  // (m_currentSrcURL) and its dest (m_dest), not about a single file.
1903  // It also means we already stated the dest, here.
1904  // On the other hand we haven't stated the src yet (we skipped doing it
1905  // to save time, since it's not necessary to rename directly!)...
1906 
1907  // Existing dest?
1908  if ( err == ERR_DIR_ALREADY_EXIST ||
1909  err == ERR_FILE_ALREADY_EXIST ||
1910  err == ERR_IDENTICAL_FILES )
1911  {
1912  // Should we skip automatically ?
1913  bool isDir = (err == ERR_DIR_ALREADY_EXIST); // ## technically, isDir means "source is dir", not "dest is dir" #######
1914  if ((isDir && m_bAutoSkipDirs) || (!isDir && m_bAutoSkipFiles)) {
1915  // Move on to next source url
1916  skipSrc(isDir);
1917  return;
1918  } else if ((isDir && m_bOverwriteAllDirs) || (!isDir && m_bOverwriteAllFiles)) {
1919  ; // nothing to do, stat+copy+del will overwrite
1920  } else if ((isDir && m_bAutoRenameDirs) || (!isDir && m_bAutoRenameFiles)) {
1921  KUrl destDirectory(m_currentDestURL); // dest including filename
1922  destDirectory.setPath(destDirectory.directory());
1923  const QString newName = KIO::RenameDialog::suggestName(destDirectory, m_currentDestURL.fileName());
1924 
1925  m_dest.setPath(m_currentDestURL.path());
1926  m_dest.setFileName(newName);
1927  KIO::Job* job = KIO::stat(m_dest, StatJob::DestinationSide, 2, KIO::HideProgressInfo);
1928  state = STATE_STATING;
1929  destinationState = DEST_NOT_STATED;
1930  q->addSubjob(job);
1931  return;
1932  } else if ( q->isInteractive() ) {
1933  QString newPath;
1934  // we lack mtime info for both the src (not stated)
1935  // and the dest (stated but this info wasn't stored)
1936  // Let's do it for local files, at least
1937  KIO::filesize_t sizeSrc = (KIO::filesize_t) -1;
1938  KIO::filesize_t sizeDest = (KIO::filesize_t) -1;
1939  time_t ctimeSrc = (time_t) -1;
1940  time_t ctimeDest = (time_t) -1;
1941  time_t mtimeSrc = (time_t) -1;
1942  time_t mtimeDest = (time_t) -1;
1943 
1944  bool destIsDir = err == ERR_DIR_ALREADY_EXIST;
1945 
1946  // ## TODO we need to stat the source using KIO::stat
1947  // so that this code is properly network-transparent.
1948 
1949  KDE_struct_stat stat_buf;
1950  if ( m_currentSrcURL.isLocalFile() &&
1951  KDE::stat(m_currentSrcURL.toLocalFile(), &stat_buf) == 0 ) {
1952  sizeSrc = stat_buf.st_size;
1953  ctimeSrc = stat_buf.st_ctime;
1954  mtimeSrc = stat_buf.st_mtime;
1955  isDir = S_ISDIR(stat_buf.st_mode);
1956  }
1957  if ( dest.isLocalFile() &&
1958  KDE::stat(dest.toLocalFile(), &stat_buf) == 0 ) {
1959  sizeDest = stat_buf.st_size;
1960  ctimeDest = stat_buf.st_ctime;
1961  mtimeDest = stat_buf.st_mtime;
1962  destIsDir = S_ISDIR(stat_buf.st_mode);
1963  }
1964 
1965  // If src==dest, use "overwrite-itself"
1966  RenameDialog_Mode mode = ( m_currentSrcURL == dest ) ? M_OVERWRITE_ITSELF : M_OVERWRITE;
1967  if (!isDir && destIsDir) {
1968  // We can't overwrite a dir with a file.
1969  mode = (RenameDialog_Mode) 0;
1970  }
1971 
1972  if ( m_srcList.count() > 1 )
1973  mode = (RenameDialog_Mode) ( mode | M_MULTI | M_SKIP );
1974  if (destIsDir)
1975  mode = (RenameDialog_Mode) ( mode | M_ISDIR );
1976 
1977  if (m_reportTimer)
1978  m_reportTimer->stop();
1979 
1980  RenameDialog_Result r = q->ui()->askFileRename(
1981  q,
1982  err != ERR_DIR_ALREADY_EXIST ? i18n("File Already Exists") : i18n("Already Exists as Folder"),
1983  m_currentSrcURL.url(),
1984  dest.url(),
1985  mode, newPath,
1986  sizeSrc, sizeDest,
1987  ctimeSrc, ctimeDest,
1988  mtimeSrc, mtimeDest );
1989 
1990  if (m_reportTimer)
1991  m_reportTimer->start(REPORT_TIMEOUT);
1992 
1993  switch ( r )
1994  {
1995  case R_CANCEL:
1996  {
1997  q->setError( ERR_USER_CANCELED );
1998  q->emitResult();
1999  return;
2000  }
2001  case R_AUTO_RENAME:
2002  if (isDir) {
2003  m_bAutoRenameDirs = true;
2004  }
2005  else {
2006  m_bAutoRenameFiles = true;
2007  }
2008  // fall through
2009  case R_RENAME:
2010  {
2011  // Set m_dest to the chosen destination
2012  // This is only for this src url; the next one will revert to m_globalDest
2013  m_dest.setPath( newPath );
2014  KIO::Job* job = KIO::stat( m_dest, StatJob::DestinationSide, 2, KIO::HideProgressInfo );
2015  state = STATE_STATING;
2016  destinationState = DEST_NOT_STATED;
2017  q->addSubjob(job);
2018  return;
2019  }
2020  case R_AUTO_SKIP:
2021  if (isDir)
2022  m_bAutoSkipDirs = true;
2023  else
2024  m_bAutoSkipFiles = true;
2025  // fall through
2026  case R_SKIP:
2027  // Move on to next url
2028  skipSrc(isDir);
2029  return;
2030  case R_OVERWRITE_ALL:
2031  if (destIsDir)
2032  m_bOverwriteAllDirs = true;
2033  else
2034  m_bOverwriteAllFiles = true;
2035  break;
2036  case R_OVERWRITE:
2037  // Add to overwrite list
2038  // Note that we add dest, not m_dest.
2039  // This ensures that when moving several urls into a dir (m_dest),
2040  // we only overwrite for the current one, not for all.
2041  // When renaming a single file (m_asMethod), it makes no difference.
2042  kDebug(7007) << "adding to overwrite list: " << dest.path();
2043  m_overwriteList.insert( dest.path() );
2044  break;
2045  default:
2046  //assert( 0 );
2047  break;
2048  }
2049  } else if ( err != KIO::ERR_UNSUPPORTED_ACTION ) {
2050  // Dest already exists, and job is not interactive -> abort with error
2051  q->setError( err );
2052  q->setErrorText( errText );
2053  q->emitResult();
2054  return;
2055  }
2056  } else if ( err != KIO::ERR_UNSUPPORTED_ACTION ) {
2057  kDebug(7007) << "Couldn't rename" << m_currentSrcURL << "to" << dest << ", aborting";
2058  q->setError( err );
2059  q->setErrorText( errText );
2060  q->emitResult();
2061  return;
2062  }
2063  kDebug(7007) << "Couldn't rename" << m_currentSrcURL << "to" << dest << ", reverting to normal way, starting with stat";
2064  //kDebug(7007) << "KIO::stat on" << m_currentSrcURL;
2065  KIO::Job* job = KIO::stat( m_currentSrcURL, StatJob::SourceSide, 2, KIO::HideProgressInfo );
2066  state = STATE_STATING;
2067  q->addSubjob(job);
2068  m_bOnlyRenames = false;
2069  }
2070  else
2071  {
2072  kDebug(7007) << "Renaming succeeded, move on";
2073  ++m_processedFiles;
2074  emit q->copyingDone( q, *m_currentStatSrc, dest, -1 /*mtime unknown, and not needed*/, true, true );
2075  m_successSrcList.append(*m_currentStatSrc);
2076  statNextSrc();
2077  }
2078 }
2079 
2080 void CopyJob::slotResult( KJob *job )
2081 {
2082  Q_D(CopyJob);
2083  //kDebug(7007) << "d->state=" << (int) d->state;
2084  // In each case, what we have to do is :
2085  // 1 - check for errors and treat them
2086  // 2 - removeSubjob(job);
2087  // 3 - decide what to do next
2088 
2089  switch ( d->state ) {
2090  case STATE_STATING: // We were trying to stat a src url or the dest
2091  d->slotResultStating( job );
2092  break;
2093  case STATE_RENAMING: // We were trying to do a direct renaming, before even stat'ing
2094  {
2095  d->slotResultRenaming( job );
2096  break;
2097  }
2098  case STATE_LISTING: // recursive listing finished
2099  //kDebug(7007) << "totalSize:" << (unsigned int) d->m_totalSize << "files:" << d->files.count() << "d->dirs:" << d->dirs.count();
2100  // Was there an error ?
2101  if (job->error())
2102  {
2103  Job::slotResult( job ); // will set the error and emit result(this)
2104  return;
2105  }
2106 
2107  removeSubjob( job );
2108  assert ( !hasSubjobs() );
2109 
2110  d->statNextSrc();
2111  break;
2112  case STATE_CREATING_DIRS:
2113  d->slotResultCreatingDirs( job );
2114  break;
2115  case STATE_CONFLICT_CREATING_DIRS:
2116  d->slotResultConflictCreatingDirs( job );
2117  break;
2118  case STATE_COPYING_FILES:
2119  d->slotResultCopyingFiles( job );
2120  break;
2121  case STATE_CONFLICT_COPYING_FILES:
2122  d->slotResultConflictCopyingFiles( job );
2123  break;
2124  case STATE_DELETING_DIRS:
2125  d->slotResultDeletingDirs( job );
2126  break;
2127  case STATE_SETTING_DIR_ATTRIBUTES:
2128  d->slotResultSettingDirAttributes( job );
2129  break;
2130  default:
2131  assert( 0 );
2132  }
2133 }
2134 
2135 void KIO::CopyJob::setDefaultPermissions( bool b )
2136 {
2137  d_func()->m_defaultPermissions = b;
2138 }
2139 
2140 KIO::CopyJob::CopyMode KIO::CopyJob::operationMode() const
2141 {
2142  return d_func()->m_mode;
2143 }
2144 
2145 void KIO::CopyJob::setAutoSkip(bool autoSkip)
2146 {
2147  d_func()->m_bAutoSkipFiles = autoSkip;
2148  d_func()->m_bAutoSkipDirs = autoSkip;
2149 }
2150 
2151 void KIO::CopyJob::setAutoRename(bool autoRename)
2152 {
2153  d_func()->m_bAutoRenameFiles = autoRename;
2154  d_func()->m_bAutoRenameDirs = autoRename;
2155 }
2156 
2157 void KIO::CopyJob::setWriteIntoExistingDirectories(bool overwriteAll) // #65926
2158 {
2159  d_func()->m_bOverwriteAllDirs = overwriteAll;
2160 }
2161 
2162 CopyJob *KIO::copy(const KUrl& src, const KUrl& dest, JobFlags flags)
2163 {
2164  //kDebug(7007) << "src=" << src << "dest=" << dest;
2165  KUrl::List srcList;
2166  srcList.append( src );
2167  return CopyJobPrivate::newJob(srcList, dest, CopyJob::Copy, false, flags);
2168 }
2169 
2170 CopyJob *KIO::copyAs(const KUrl& src, const KUrl& dest, JobFlags flags)
2171 {
2172  //kDebug(7007) << "src=" << src << "dest=" << dest;
2173  KUrl::List srcList;
2174  srcList.append( src );
2175  return CopyJobPrivate::newJob(srcList, dest, CopyJob::Copy, true, flags);
2176 }
2177 
2178 CopyJob *KIO::copy( const KUrl::List& src, const KUrl& dest, JobFlags flags )
2179 {
2180  //kDebug(7007) << src << dest;
2181  return CopyJobPrivate::newJob(src, dest, CopyJob::Copy, false, flags);
2182 }
2183 
2184 CopyJob *KIO::move(const KUrl& src, const KUrl& dest, JobFlags flags)
2185 {
2186  //kDebug(7007) << src << dest;
2187  KUrl::List srcList;
2188  srcList.append( src );
2189  CopyJob* job = CopyJobPrivate::newJob(srcList, dest, CopyJob::Move, false, flags);
2190  ClipboardUpdater::create(job, ClipboardUpdater::UpdateContent);
2191  return job;
2192 }
2193 
2194 CopyJob *KIO::moveAs(const KUrl& src, const KUrl& dest, JobFlags flags)
2195 {
2196  //kDebug(7007) << src << dest;
2197  KUrl::List srcList;
2198  srcList.append( src );
2199  CopyJob* job = CopyJobPrivate::newJob(srcList, dest, CopyJob::Move, true, flags);
2200  ClipboardUpdater::create(job, ClipboardUpdater::UpdateContent);
2201  return job;
2202 }
2203 
2204 CopyJob *KIO::move( const KUrl::List& src, const KUrl& dest, JobFlags flags)
2205 {
2206  //kDebug(7007) << src << dest;
2207  CopyJob* job = CopyJobPrivate::newJob(src, dest, CopyJob::Move, false, flags);
2208  ClipboardUpdater::create(job, ClipboardUpdater::UpdateContent);
2209  return job;
2210 }
2211 
2212 CopyJob *KIO::link(const KUrl& src, const KUrl& destDir, JobFlags flags)
2213 {
2214  KUrl::List srcList;
2215  srcList.append( src );
2216  return CopyJobPrivate::newJob(srcList, destDir, CopyJob::Link, false, flags);
2217 }
2218 
2219 CopyJob *KIO::link(const KUrl::List& srcList, const KUrl& destDir, JobFlags flags)
2220 {
2221  return CopyJobPrivate::newJob(srcList, destDir, CopyJob::Link, false, flags);
2222 }
2223 
2224 CopyJob *KIO::linkAs(const KUrl& src, const KUrl& destDir, JobFlags flags )
2225 {
2226  KUrl::List srcList;
2227  srcList.append( src );
2228  return CopyJobPrivate::newJob(srcList, destDir, CopyJob::Link, false, flags);
2229 }
2230 
2231 CopyJob *KIO::trash(const KUrl& src, JobFlags flags)
2232 {
2233  KUrl::List srcList;
2234  srcList.append( src );
2235  return CopyJobPrivate::newJob(srcList, KUrl( "trash:/" ), CopyJob::Move, false, flags);
2236 }
2237 
2238 CopyJob *KIO::trash(const KUrl::List& srcList, JobFlags flags)
2239 {
2240  return CopyJobPrivate::newJob(srcList, KUrl( "trash:/" ), CopyJob::Move, false, flags);
2241 }
2242 
2243 #include "copyjob.moc"
KIO::UDSEntry::UDS_URL
An alternative URL (If different from the caption).
Definition: udsentry.h:190
kdirlister.h
KIO::CopyJob::Link
Definition: copyjob.h:73
STATE_DELETING_DIRS
Definition: copyjob.cpp:94
i18n
QString i18n(const char *text)
KIO::Overwrite
When set, automatically overwrite the destination if it exists already.
Definition: jobclasses.h:67
KIO::filesize_t
qulonglong filesize_t
64-bit file size
Definition: global.h:57
KUrl::directory
QString directory(const DirectoryOptions &options=IgnoreTrailingSlash) const
KUrl::RemoveTrailingSlash
OrgKdeKDirNotifyInterface::emitFileRenamed
static void emitFileRenamed(const QString &src, const QString &dst)
Definition: kdirnotify.cpp:37
KDirWatch::self
static KDirWatch * self()
KIO::ERR_DISK_FULL
Definition: global.h:256
KIO::UDSEntry::isLink
bool isLink() const
Definition: udsentry.cpp:89
STATE_CONFLICT_COPYING_FILES
Definition: copyjob.cpp:93
KIO::S_SKIP
Definition: skipdialog.h:29
KIO::Job::addMetaData
void addMetaData(const QString &key, const QString &value)
Add key/value pair to the meta data that is sent to the slave.
Definition: job.cpp:264
KFileSystemType::Type
Type
KConfigGroup::writePathEntry
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
kio_resolve_local_urls
bool kio_resolve_local_urls
Definition: copyjob.cpp:298
kdebug.h
KIO::CopyJob::destUrl
KUrl destUrl() const
Returns the destination URL.
Definition: copyjob.cpp:273
KIO::CopyJob::setAutoSkip
void setAutoSkip(bool autoSkip)
Skip copying or moving any file when the destination already exists, instead of the default behavior ...
Definition: copyjob.cpp:2145
KCompositeJob::emitResult
void emitResult()
DEST_DOESNT_EXIST
Definition: copyjob.cpp:67
KUrl::AddTrailingSlash
KIO::CopyInfo::permissions
int permissions
Definition: copyjob.h:46
KCompositeJob::setUiDelegate
void setUiDelegate(KJobUiDelegate *delegate)
KTemporaryFile::setPrefix
void setPrefix(const QString &prefix)
KIO::UDSEntry
Universal Directory Service.
Definition: udsentry.h:58
KIO::Scheduler::setJobPriority
static void setJobPriority(SimpleJob *job, int priority)
Changes the priority of job; jobs of the same priority run in the order in which they were created...
Definition: scheduler.cpp:805
kdirwatch.h
timeout
int timeout
KIO::R_OVERWRITE
Definition: renamedialog.h:61
KIO::ListJob
A ListJob is allows you to get the get the content of a directory.
Definition: jobclasses.h:936
kdirnotify.h
KFileItem::isNull
bool isNull() const
Return true if default-constructed.
Definition: kfileitem.cpp:1720
KIO::S_AUTO_SKIP
Definition: skipdialog.h:29
slave.h
KIO::HideProgressInfo
Hide progress information dialog, i.e.
Definition: jobclasses.h:51
KIO::ERR_CANNOT_DELETE
Definition: global.h:235
KIO::CopyInfo::uSource
KUrl uSource
Definition: copyjob.h:43
KIO::ERR_FILE_ALREADY_EXIST
Definition: global.h:206
dirs
KStandardDirs * dirs()
KIO::ERR_USER_CANCELED
Definition: global.h:214
KIO::mkdir
SimpleJob * mkdir(const KUrl &url, int permissions=-1)
Creates a single directory.
Definition: job.cpp:697
KDE::stat
int stat(const QString &path, KDE_struct_stat *buf)
KDE::rename
int rename(const QString &in, const QString &out)
KIO::UDSEntry::isDir
bool isDir() const
Definition: udsentry.cpp:84
KIO::SimpleJob::url
const KUrl & url() const
Returns the SimpleJob's URL.
Definition: job.cpp:341
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KIO::stat
StatJob * stat(const KUrl &url, JobFlags flags=DefaultFlags)
Find all details for one file or directory.
Definition: job.cpp:924
f
static quint32 f(DES_KEY *key, quint32 r, char *subkey)
Definition: des.cpp:378
KIO::FileCopyJob::setSourceSize
void setSourceSize(KIO::filesize_t size)
If you know the size of the source file, call this method to inform this job.
Definition: job.cpp:2084
REPORT_TIMEOUT
#define REPORT_TIMEOUT
Definition: copyjob.cpp:61
STATE_STATING
Definition: copyjob.cpp:87
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KIO::StatJob
A KIO job that retrieves information about a file or directory.
Definition: jobclasses.h:440
KDirLister::cachedItemForUrl
static KFileItem cachedItemForUrl(const KUrl &url)
Return the KFileItem for the given URL, if we listed it recently and it's still in the cache - which ...
Definition: kdirlister.cpp:2783
KIO::ClipboardUpdater::UpdateContent
Definition: clipboardupdater_p.h:55
DEST_NOT_STATED
Definition: copyjob.cpp:64
KIO::file_move
FileCopyJob * file_move(const KUrl &src, const KUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
Move a single file.
Definition: job.cpp:2495
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
KIO::UDSEntry::UDS_LOCAL_PATH
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
Definition: udsentry.h:166
STATE_CREATING_DIRS
Definition: copyjob.cpp:90
QString
KTemporaryFile
KIO::Job::removeSubjob
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
Definition: job.cpp:118
KIO::CopyInfo::mtime
time_t mtime
Definition: copyjob.h:48
kdesktopfile.h
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
STATE_RENAMING
Definition: copyjob.cpp:88
CopyJobState
CopyJobState
States: STATE_STATING for the dest statCurrentSrc then does, for each src url: STATE_RENAMING if dire...
Definition: copyjob.cpp:86
KIO::R_OVERWRITE_ALL
Definition: renamedialog.h:61
KProtocolManager::canRenameToFile
static bool canRenameToFile(const KUrl &url)
Returns whether the protocol can rename (i.e.
Definition: kprotocolmanager.cpp:1142
OrgKdeKDirNotifyInterface::emitFilesAdded
static void emitFilesAdded(const QString &directory)
Definition: kdirnotify.cpp:47
KIO::M_OVERWRITE_ITSELF
Definition: renamedialog.h:56
KUrl
KIO::copyAs
CopyJob * copyAs(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Copy a file or directory src into the destination dest, which is the destination name in any case...
Definition: copyjob.cpp:2170
KFileSystemType::fileSystemType
Type fileSystemType(const QString &path)
KIO::ListJob::setUnrestricted
void setUnrestricted(bool unrestricted)
Do not apply any KIOSK restrictions to this job.
Definition: job.cpp:2749
DestinationState
DestinationState
Definition: copyjob.cpp:63
config
KSharedConfigPtr config()
KIO::SkipDialog_Result
SkipDialog_Result
Definition: skipdialog.h:29
kprotocolmanager.h
KDirWatch::stopDirScan
bool stopDirScan(const QString &path)
KUrl::setPath
void setPath(const QString &path)
KIO::CopyJob::srcUrls
KUrl::List srcUrls() const
Returns the list of source URLs.
Definition: copyjob.cpp:268
scheduler.h
KIO::CopyJob::Move
Definition: copyjob.h:73
KIO::DefaultFlags
Show the progress info GUI, no Resume and no Overwrite.
Definition: jobclasses.h:46
KIO::StatJob::DestinationSide
Definition: jobclasses.h:447
KIO::CopyJob::CopyJob
CopyJob(CopyJobPrivate &dd)
Definition: copyjob.cpp:256
KIO::R_CANCEL
Definition: renamedialog.h:61
kdiskfreespaceinfo.h
KUrl::addPath
void addPath(const QString &txt)
OrgKdeKDirNotifyInterface::emitFilesRemoved
static void emitFilesRemoved(const QStringList &fileList)
Definition: kdirnotify.cpp:57
KIO::SimpleJobPrivate::newJobNoUi
static SimpleJob * newJobNoUi(const KUrl &url, int command, const QByteArray &packedArgs)
Definition: job_p.h:199
KIO::file_copy
FileCopyJob * file_copy(const KUrl &src, const KUrl &dest, int permissions=-1, JobFlags flags=DefaultFlags)
Copy a single file.
Definition: job.cpp:2489
KIO::ERR_CANNOT_OPEN_FOR_WRITING
Definition: global.h:196
KFileSystemType::Ramfs
KIO::FileCopyJob::setModificationTime
void setModificationTime(const QDateTime &mtime)
Sets the modification time of the file.
Definition: job.cpp:2092
KIO::CopyJob::setWriteIntoExistingDirectories
void setWriteIntoExistingDirectories(bool overwriteAllDirs)
Reuse any directory that already exists, instead of the default behavior (interactive mode: showing a...
Definition: copyjob.cpp:2157
KIO::UDSEntry::numberValue
long long numberValue(uint field, long long defaultValue=0) const
Definition: udsentry.cpp:78
KProtocolManager::supportsDeleting
static bool supportsDeleting(const KUrl &url)
Returns whether the protocol can delete files/objects.
Definition: kprotocolmanager.cpp:1077
STATE_LISTING
Definition: copyjob.cpp:89
KIO::encodeFileName
QString encodeFileName(const QString &str)
Encodes (from the text displayed to the real filename) This translates '/' into a "unicode fraction s...
Definition: global.cpp:146
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:39
KUrl::user
QString user() const
KIO::CopyJob::~CopyJob
virtual ~CopyJob()
Definition: copyjob.cpp:264
KUrl::protocol
QString protocol() const
KUrl::pass
QString pass() const
KCompositeJob::slotResult
virtual void slotResult(KJob *job)
QStringList
KIO::buildErrorString
QString buildErrorString(int errorCode, const QString &errorText)
Returns a translated error message for errorCode using the additional error information provided by e...
Definition: global.cpp:164
KUrl::setPass
void setPass(const QString &pass)
KIO::UDSEntry::stringValue
QString stringValue(uint field) const
Definition: udsentry.cpp:73
copyjob.h
KIO::getJobTracker
KJobTrackerInterface * getJobTracker()
Definition: global.cpp:1246
KIO::Job::metaData
MetaData metaData() const
Get meta data received from the slave.
Definition: job.cpp:248
KIO::rmdir
SimpleJob * rmdir(const KUrl &url)
Removes a single directory.
Definition: job.cpp:704
KIO::link
CopyJob * link(const KUrl &src, const KUrl &destDir, JobFlags flags=DefaultFlags)
Create a link.
Definition: copyjob.cpp:2212
KIO::R_AUTO_SKIP
Definition: renamedialog.h:61
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KIO::ERR_IDENTICAL_FILES
Definition: global.h:257
KIO::RenameDialog_Mode
RenameDialog_Mode
M_OVERWRITE: We have an existing dest, show details about it and offer to overwrite it...
Definition: renamedialog.h:56
KIO::Job::doSuspend
virtual bool doSuspend()
Suspend this job.
Definition: job.cpp:186
KIO::CopyJob::Copy
Definition: copyjob.h:73
KIO::CMD_RENAME
Definition: global.h:165
KIO::R_SKIP
Definition: renamedialog.h:61
KIO::CopyJob::setDefaultPermissions
void setDefaultPermissions(bool b)
By default the permissions of the copied files will be those of the source files. ...
Definition: copyjob.cpp:2135
KIO::ERR_DIR_ALREADY_EXIST
Definition: global.h:207
KIO::M_SKIP
Definition: renamedialog.h:56
KIO::UDSEntry::UDS_MODIFICATION_TIME
The last time the file was modified.
Definition: udsentry.h:173
jobuidelegate.h
KIO::move
CopyJob * move(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Moves a file or directory src to the given destination dest.
Definition: copyjob.cpp:2184
KIO::symlink
SimpleJob * symlink(const QString &target, const KUrl &dest, JobFlags flags=DefaultFlags)
Create or move a symlink.
Definition: job.cpp:738
KIO::R_RENAME
Definition: renamedialog.h:61
QSet< QString >
KIO::UDSEntry::contains
bool contains(uint field) const
check existence of a field
Definition: udsentry.cpp:118
KDesktopFile
KIO::setModificationTime
SimpleJob * setModificationTime(const KUrl &url, const QDateTime &mtime)
Changes the modification time on a file or directory.
Definition: job.cpp:724
KDE::lstat
int lstat(const QString &path, KDE_struct_stat *buf)
KIO::ClipboardUpdater::create
static ClipboardUpdater * create(Job *job, Mode mode)
Returns an instance of clipboard updater if QApplication::type() does not return a tty...
Definition: clipboardupdater.cpp:162
QDateTime
KIO::moveAs
CopyJob * moveAs(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Moves a file or directory src to the given destination dest.
Definition: copyjob.cpp:2194
KIO::CopyJob::slotResult
virtual void slotResult(KJob *job)
Definition: copyjob.cpp:2080
KConfigGroup
KIO::del
DeleteJob * del(const KUrl &src, JobFlags flags=DefaultFlags)
Delete a file or directory.
Definition: deletejob.cpp:492
job_p.h
STATE_CONFLICT_CREATING_DIRS
Definition: copyjob.cpp:91
KUrl::List
KIO::M_ISDIR
Definition: renamedialog.h:56
KIO::CopyInfo::uDest
KUrl uDest
Definition: copyjob.h:44
ktemporaryfile.h
KIO::Job::setParentJob
void setParentJob(Job *parentJob)
Set the parent Job.
Definition: job.cpp:235
KIO::CopyJob::CopyMode
CopyMode
Defines the mode of the operation.
Definition: copyjob.h:73
KIO::R_AUTO_RENAME
Definition: renamedialog.h:61
kfilesystemtype_p.h
KFileSystemType::Nfs
KProtocolInfo::FileNameUsedForCopying
FileNameUsedForCopying
KIO::linkAs
CopyJob * linkAs(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Create a link.
Definition: copyjob.cpp:2224
KRecentDirs::dir
QString dir(const QString &fileClass)
Returns the most recently used directory accociated with this file-class.
Definition: krecentdirs.cpp:68
KIO::M_OVERWRITE
Definition: renamedialog.h:56
KIO::Job::errorString
QString errorString() const
Converts an error code and a non-i18n error message into an error message in the current language...
Definition: global.cpp:159
KIO::UDSEntry::UDS_ACCESS
Access permissions (part of the mode returned by stat)
Definition: udsentry.h:171
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
KProtocolInfo::FromUrl
KIO::FileCopyJob
The FileCopyJob copies data from one place to another.
Definition: jobclasses.h:856
KIO::listRecursive
ListJob * listRecursive(const KUrl &url, JobFlags flags=DefaultFlags, bool includeHidden=true)
The same as the previous method, but recurses subdirectories.
Definition: job.cpp:2744
KIO::UDSEntry::UDS_NAME
Filename - as displayed in directory listings etc.
Definition: udsentry.h:163
KIO::UDSEntry::UDS_LINK_DEST
Name of the file where the link points to Allows to check for a symlink (don't use S_ISLNK !) ...
Definition: udsentry.h:184
DEST_IS_FILE
Definition: copyjob.cpp:66
KIO::ERR_UNSUPPORTED_ACTION
Definition: global.h:202
KIO_ARGS
#define KIO_ARGS
Definition: job_p.h:32
KUrl::ObeyTrailingSlash
KIO::CopyJob::doSuspend
virtual bool doSuspend()
Reimplemented for internal reasons.
Definition: copyjob.cpp:484
KIO::RenameDialog_Result
RenameDialog_Result
The result of open_RenameDialog().
Definition: renamedialog.h:61
KIO::Job
The base class for all jobs.
Definition: jobclasses.h:94
KIO::copy
CopyJob * copy(const KUrl &src, const KUrl &dest, JobFlags flags=DefaultFlags)
Copy a file or directory src into the destination dest, which can be a file (including the final file...
Definition: copyjob.cpp:2162
KProtocolInfo::Name
KIO::RenameDialog::suggestName
static QString suggestName(const KUrl &baseURL, const QString &oldName)
Given a directory path and a filename (which usually exists already), this function returns a suggest...
Definition: renamedialog.cpp:419
KIO::UDSEntry::UDS_CREATION_TIME
The time the file was created.
Definition: udsentry.h:177
KUrl::AppendTrailingSlash
KFileSystemType::Smb
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KIO::UDSEntry::UDS_DISPLAY_NAME
If set, contains the label to display instead of the 'real name' in UDS_NAME.
Definition: udsentry.h:211
KIO::CopyJob::setAutoRename
void setAutoRename(bool autoRename)
Rename files automatically when the destination already exists, instead of the default behavior (inte...
Definition: copyjob.cpp:2151
KCompositeJob::hasSubjobs
bool hasSubjobs()
STATE_SETTING_DIR_ATTRIBUTES
Definition: copyjob.cpp:95
KIO::ERR_CANNOT_SYMLINK
Definition: global.h:254
STATE_COPYING_FILES
Definition: copyjob.cpp:92
deletejob.h
KIO::CopyInfo
Definition: copyjob.h:41
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
KIO::StatJob::SourceSide
Definition: jobclasses.h:446
KProtocolManager::supportsListing
static bool supportsListing(const KUrl &url)
Returns whether the protocol can list files/objects.
Definition: kprotocolmanager.cpp:1032
KConfigGroup::sync
void sync()
KIO::CopyJob::emitResult
void emitResult()
Definition: copyjob.cpp:1745
KIO::CopyInfo::ctime
time_t ctime
Definition: copyjob.h:47
KJobTrackerInterface::registerJob
virtual void registerJob(KJob *job)
DEST_IS_DIR
Definition: copyjob.cpp:65
clipboardupdater_p.h
KFileItem::entry
KIO::UDSEntry entry() const
Returns the UDS entry.
Definition: kfileitem.cpp:1678
KUrl::isLocalFile
bool isLocalFile() const
KIO::CopyJob::operationMode
CopyMode operationMode() const
Returns the mode of the operation (copy, move, or link), depending on whether KIO::copy(), KIO::move() or KIO::link() was called.
Definition: copyjob.cpp:2140
KIO::JobPrivate
Definition: job_p.h:37
KProtocolManager::fileNameUsedForCopying
static KProtocolInfo::FileNameUsedForCopying fileNameUsedForCopying(const KUrl &url)
This setting defines the strategy to use for generating a filename, when copying a file or directory ...
Definition: kprotocolmanager.cpp:1160
end
const KShortcut & end()
utime
int utime(const QString &filename, struct utimbuf *buf)
KProtocolManager::canRenameFromFile
static bool canRenameFromFile(const KUrl &url)
Returns whether the protocol can rename (i.e.
Definition: kprotocolmanager.cpp:1132
KJob
KDirWatch::restartDirScan
bool restartDirScan(const QString &path)
KIO::UDSEntry::UDS_SIZE
Size of the file.
Definition: udsentry.h:144
kfileitem.h
KUrl::prettyUrl
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
KProtocolInfo::DisplayName
KIO::trash
CopyJob * trash(const KUrl &src, JobFlags flags=DefaultFlags)
Trash a file or directory.
Definition: copyjob.cpp:2231
KFileItem::mostLocalUrl
KUrl mostLocalUrl(bool &local) const
Tries to give a local URL for this file item if possible.
Definition: kfileitem.cpp:1476
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:45
KIO::CopyJob
CopyJob is used to move, copy or symlink files and directories.
Definition: copyjob.h:65
QList
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
OrgKdeKDirNotifyInterface::emitFileMoved
static void emitFileMoved(const QString &src, const QString &dst)
Definition: kdirnotify.cpp:42
KIO::CopyInfo::size
KIO::filesize_t size
Definition: copyjob.h:49
KIO::SimpleJob
A simple job (one url and one command).
Definition: jobclasses.h:322
KIO::M_MULTI
Definition: renamedialog.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal