~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/core/filesystemmusicstorage.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
*/
17
17
 
18
18
#include "filesystemmusicstorage.h"
 
19
#include "core/logging.h"
19
20
 
20
21
#include <QDir>
21
22
#include <QFile>
 
23
#include <QUrl>
22
24
 
23
25
FilesystemMusicStorage::FilesystemMusicStorage(const QString& root)
24
26
  : root_(root)
26
28
}
27
29
 
28
30
bool FilesystemMusicStorage::CopyToStorage(const CopyJob& job) {
29
 
  const QString dest_filename = root_ + "/" + job.destination_;
 
31
  const QFileInfo src = QFileInfo(job.source_);
 
32
  const QFileInfo dest = QFileInfo(root_ + "/" + job.destination_ );
30
33
 
31
34
  // Don't do anything if the destination is the same as the source
32
 
  if (job.source_ == dest_filename)
 
35
  if (src == dest)
33
36
    return true;
34
37
 
35
38
  // Create directories as required
36
 
  const QString dest_directory = dest_filename.section('/', 0, -2);
37
39
  QDir dir;
38
 
  if (!dir.mkpath(dest_directory)) {
39
 
    qWarning() << "Failed to create directory" << dest_directory;
 
40
  if (!dir.mkpath(dest.absolutePath())) {
 
41
    qLog(Warning) << "Failed to create directory" << dest.dir().absolutePath();
40
42
    return false;
41
43
  }
42
44
 
43
45
  // Remove the destination file if it exists and we want to overwrite
44
 
  if (job.overwrite_ && QFile::exists(dest_filename))
45
 
    QFile::remove(dest_filename);
 
46
  if (job.overwrite_ && dest.exists())
 
47
    QFile::remove(dest.absoluteFilePath());
46
48
 
47
49
  // Copy or move
48
50
  if (job.remove_original_)
49
 
    return QFile::rename(job.source_, dest_filename);
 
51
    return QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
50
52
  else
51
 
    return QFile::copy(job.source_, dest_filename);
 
53
    return QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
52
54
}
53
55
 
54
56
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob& job) {
55
 
  return QFile::remove(job.metadata_.filename());
 
57
  return QFile::remove(job.metadata_.url().toLocalFile());
56
58
}