bool FileSystem::rename(const std::string &oldname, const std::string &newname) { std::string oldpath(normalize_path(oldname)); std::string newpath(normalize_path(newname)); if (std::rename(oldpath.c_str(), newpath.c_str()) != 0) return false; return true; }
static JSVAL fs_rename(JSARGS args) { HandleScope scope; String::Utf8Value oldpath(args[0]->ToString()); String::Utf8Value newpath(args[1]->ToString()); return scope.Close(Integer::New(rename(*oldpath, *newpath))); }
void RecurseWorker::updateTrackInfo( const TrackInfo &trackInfo ) { bool tagsChanged = false; TrackInfo ti = trackInfo; TrackInfo oldTags; QString oldpath( trackInfo.mDirectory + "/" + trackInfo.mFileName ); mTagMap.clear(); { TagLib::FileRef f( oldpath.toLocal8Bit().data() ); if( f.file() ) { oldTags = trackInfo; TagLib::AudioProperties *audioProperties = f.audioProperties(); TagLib::Tag *tag = f.tag(); if( audioProperties ) { oldTags.mPlayTime = audioProperties->length(); } if( tag ) { oldTags.mArtist = QString::fromUtf8( tag->artist().toCString( true ) ); oldTags.mTitle = QString::fromUtf8( tag->title().toCString( true ) ); oldTags.mAlbum = QString::fromUtf8( tag->album().toCString( true ) ); oldTags.mTrackNr = tag->track(); oldTags.mYear = tag->year(); oldTags.mGenre = QString::fromUtf8( tag->genre().toCString( true ) ); } else { emit error( tr("Could not read tags"), oldpath ); } ti = oldTags; } else { emit error( tr("Could not read file"), oldpath ); } } switch( mMode ) { case ModeSetTags: if( mSetArtist ) { ti.mArtist = mTrackInfo.mArtist; } if( mSetTitle ) { ti.mTitle.append( " " ); ti.mTitle.append( mTrackInfo.mTitle ); } if( mSetAlbum ) { ti.mAlbum = mTrackInfo.mAlbum; } if( mSetYear ) { ti.mYear = mTrackInfo.mYear; } if( mSetGenre ) { ti.mGenre = mTrackInfo.mGenre; } tagsChanged = (ti != oldTags); if( mSetFlags ) { if( mTrackInfo.isFlagged( TrackInfo::Favorite ) ) { ti.setFlag( TrackInfo::Favorite, true ); } if( mTrackInfo.isFlagged( TrackInfo::Unwanted ) ) { ti.setFlag( TrackInfo::Unwanted, true ); } } if( mUnsetFlags ) { if( mTrackInfo.isFlagged( TrackInfo::Favorite ) ) { ti.setFlag( TrackInfo::Favorite, false ); } if( mTrackInfo.isFlagged( TrackInfo::Unwanted ) ) { ti.setFlag( TrackInfo::Unwanted, false ); } if( mTrackInfo.isFlagged( TrackInfo::ScannedWithPower ) || mTrackInfo.isFlagged( TrackInfo::ScannedWithPeak ) ) { ti.setFlag( TrackInfo::ScannedWithPeak, false ); ti.mLastScanned = 0; } } if( mSetGroups || mUnsetGroups ) { QStringList groups( mTrackInfo.getGroups() ); foreach( const QString &group, groups ) { ti.setGroup( group, mSetGroups ); } }