Commit 980fdcac authored by Matěj Laitl's avatar Matěj Laitl
Browse files

IpodCollection: Don't hit ulimit -n when copying covers

This was because QTemporaryFile holds its file open. It cannot be
forced to close its file, so use slightly more dumb solution.

BUG: 301207
FIXED-IN: 2.6
parent 49827e90
......@@ -8,6 +8,7 @@ VERSION 2.6
argument.
BUGFIXES:
* Don't hit "too many open files" when copying covers to iPod. (BR 301207)
* Don't crash if iPod's eject button is hit twice. (BR 301208)
* Don't crash even if the iPod is connected and quickly ejected. (BR 301166)
......
......@@ -40,6 +40,7 @@
#include <solid/storageaccess.h>
#include <ThreadWeaver/Weaver>
#include <QTemporaryFile>
#include <QWeakPointer>
#include <gpod/itdb.h>
......
......@@ -48,7 +48,6 @@ gpointer AmarokItdbUserDataDuplicateFunc( gpointer userdata )
Track::Track( Itdb_Track *ipodTrack )
: m_track( ipodTrack )
, m_tempImageFile( 0 )
{
Q_ASSERT( m_track != 0 );
m_track->usertype = m_gpodTrackUserTypeAmarokTrackPtr;
......@@ -58,7 +57,6 @@ Track::Track( Itdb_Track *ipodTrack )
Track::Track( const Meta::TrackPtr &origTrack )
: m_track( itdb_track_new() )
, m_tempImageFile( 0 )
{
Q_ASSERT( m_track != 0 );
m_track->usertype = m_gpodTrackUserTypeAmarokTrackPtr;
......@@ -132,7 +130,8 @@ Track::Track( const Meta::TrackPtr &origTrack )
Track::~Track()
{
itdb_track_free( m_track );
delete m_tempImageFile;
if( !m_tempImageFilePath.isEmpty() )
QFile::remove( m_tempImageFilePath );
}
bool
......@@ -281,12 +280,11 @@ void
Track::setImage( const QImage &newImage, bool doCommit )
{
QWriteLocker locker( &m_trackLock );
if( !m_tempImageFilePath.isEmpty() )
QFile::remove( m_tempImageFilePath );
m_tempImageFilePath.clear();
if( newImage.isNull() )
{
itdb_track_remove_thumbnails( m_track );
delete m_tempImageFile;
m_tempImageFile = 0;
}
else
{
// we set artwork even for devices that don't support it, everyone has new-enough iPod nowadays
......@@ -297,14 +295,16 @@ Track::setImage( const QImage &newImage, bool doCommit )
else
image = newImage;
delete m_tempImageFile; // delete possible previous temporary file
m_tempImageFile = new KTemporaryFile();
m_tempImageFile->setSuffix( QString( ".png" ) );
KTemporaryFile tempImageFile;
tempImageFile.setAutoRemove( false );
tempImageFile.setSuffix( QString( ".png" ) );
// we save the file to disk rather than pass image data to save several megabytes of RAM
if( m_tempImageFile->open() && image.save( m_tempImageFile, "PNG" ) )
if( tempImageFile.open() )
m_tempImageFilePath = tempImageFile.fileName();
if( tempImageFile.isOpen() && image.save( &tempImageFile, "PNG" ) )
/* this function remembers image path, it also fogots previous images (if any)
* and sets artwork_size, artwork_count and has_artwork m_track fields */
itdb_track_set_thumbnails( m_track, QFile::encodeName( m_tempImageFile->fileName() ) );
itdb_track_set_thumbnails( m_track, QFile::encodeName( m_tempImageFilePath ) );
}
m_changedFields.insert( Meta::valImage, newImage );
locker.unlock();
......
......@@ -17,10 +17,8 @@
#ifndef IPODMETA_H
#define IPODMETA_H
#include "core/meta/Meta.h"
#include "MetaValues.h"
#include <KTemporaryFile>
#include "core/meta/Meta.h"
#include <QReadWriteLock>
......@@ -212,9 +210,10 @@ namespace IpodMeta
/**
* We need the temporary image file to exist for the lifetime of Track because
* calling itdb_track_set_thumbnails() only saves the filename - the file is
* read only when needed
* read only when needed. If this path is non-empty, it means that the file
* should be deleted in destructor.
*/
KTemporaryFile *m_tempImageFile;
QString m_tempImageFilePath;
/**
* Set of field types (identified by constants from MetaValues.h) changed by
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment