forked from upstream-mirrors/OpenTracks
Bug fix: delete a partially inserted track if unable to import
This commit is contained in:
@@ -489,41 +489,53 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
* @param trackId the track id. -1L to insert a new track
|
* @param trackId the track id. -1L to insert a new track
|
||||||
* @param driveFile the drive file
|
* @param driveFile the drive file
|
||||||
*/
|
*/
|
||||||
private boolean updateTrack(long trackId, File driveFile) throws IOException {
|
private boolean updateTrack(final long trackId, File driveFile) throws IOException {
|
||||||
Track track = importDriveFile(trackId, driveFile);
|
Track track = null;
|
||||||
if (track == null) {
|
boolean success = false;
|
||||||
return false;
|
try {
|
||||||
}
|
track = importDriveFile(trackId, driveFile);
|
||||||
File updatedDriveFile;
|
if (track == null) {
|
||||||
String trackName = FileUtils.getName(driveFile.getTitle());
|
return false;
|
||||||
if (SyncUtils.isInMyTracks(driveFile, getFolderId()) && !track.getName().equals(trackName)) {
|
}
|
||||||
track.setName(trackName);
|
File updatedDriveFile;
|
||||||
|
String trackName = FileUtils.getName(driveFile.getTitle());
|
||||||
|
if (SyncUtils.isInMyTracks(driveFile, getFolderId()) && !track.getName().equals(trackName)) {
|
||||||
|
track.setName(trackName);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The drive file title and the track name inside the drive file do not
|
* The drive file title and the track name inside the drive file do not
|
||||||
* match, update the drive file.
|
* match, update the drive file.
|
||||||
*/
|
*/
|
||||||
java.io.File file = null;
|
java.io.File file = null;
|
||||||
try {
|
try {
|
||||||
file = SyncUtils.getTempFile(context, myTracksProviderUtils, track, true);
|
file = SyncUtils.getTempFile(context, myTracksProviderUtils, track, true);
|
||||||
updatedDriveFile = SyncUtils.updateDriveFile(
|
updatedDriveFile = SyncUtils.updateDriveFile(
|
||||||
drive, driveFile, trackName + "." + KmzTrackExporter.KMZ_EXTENSION, file, true);
|
drive, driveFile, trackName + "." + KmzTrackExporter.KMZ_EXTENSION, file, true);
|
||||||
|
|
||||||
if (updatedDriveFile == null) {
|
if (updatedDriveFile == null) {
|
||||||
Log.e(TAG, "Unable to update drive file");
|
Log.e(TAG, "Unable to update drive file");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (file != null) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} else {
|
||||||
if (file != null) {
|
updatedDriveFile = driveFile;
|
||||||
file.delete();
|
}
|
||||||
|
|
||||||
|
SyncUtils.updateTrack(myTracksProviderUtils, track, updatedDriveFile);
|
||||||
|
success = true;
|
||||||
|
return true;
|
||||||
|
} finally {
|
||||||
|
if (!success) {
|
||||||
|
// if the track is new, delete it
|
||||||
|
if (trackId == -1L && track != null) {
|
||||||
|
myTracksProviderUtils.deleteTrack(track.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
updatedDriveFile = driveFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncUtils.updateTrack(myTracksProviderUtils, track, updatedDriveFile);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user