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_ );
31
34
// Don't do anything if the destination is the same as the source
32
if (job.source_ == dest_filename)
35
38
// Create directories as required
36
const QString dest_directory = dest_filename.section('/', 0, -2);
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();
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());
48
50
if (job.remove_original_)
49
return QFile::rename(job.source_, dest_filename);
51
return QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
51
return QFile::copy(job.source_, dest_filename);
53
return QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
54
56
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob& job) {
55
return QFile::remove(job.metadata_.filename());
57
return QFile::remove(job.metadata_.url().toLocalFile());