mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-10-21 06:52:18 +02:00
refactor(io): use deleteFileQuietly for exists-then-delete
Add deleteFileQuietly to file_access.dart (exists check, delete, swallow
errors) and use it for the try/exists/delete/catch (_) {} copies.
This commit is contained in:
1 parent
b5cf97881f
commit
0797085385
9 files changed
+23
-42
No files matched your search
@@ -69,9 +69,7 @@ extension _DownloadQueuePaths on DownloadQueueNotifier {
|
||||
return false;
|
||||
} finally {
|
||||
if (probe != null) {
|
||||
try {
|
||||
if (await probe.exists()) await probe.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(probe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:spotiflac_android/services/ffmpeg_service.dart';
|
||||
import 'package:spotiflac_android/services/library_collections_database.dart';
|
||||
import 'package:spotiflac_android/services/library_collections_hydration.dart';
|
||||
import 'package:spotiflac_android/services/collection_track_batch.dart';
|
||||
import 'package:spotiflac_android/utils/file_access.dart';
|
||||
import 'package:spotiflac_android/utils/logger.dart';
|
||||
|
||||
export 'package:spotiflac_android/models/library_collections.dart';
|
||||
@@ -684,10 +685,7 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
|
||||
});
|
||||
_invalidatePlaylistPickerSummaries();
|
||||
if (previousCoverPath != null && previousCoverPath != destPath) {
|
||||
try {
|
||||
final previous = File(previousCoverPath);
|
||||
if (await previous.exists()) await previous.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(File(previousCoverPath));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -737,10 +735,7 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
|
||||
await File(tempPath).rename(destPath);
|
||||
return destPath;
|
||||
} finally {
|
||||
try {
|
||||
final temp = File(tempPath);
|
||||
if (await temp.exists()) await temp.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(File(tempPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -862,9 +857,7 @@ class LibraryCollectionsNotifier extends Notifier<LibraryCollectionsState> {
|
||||
sourcePath,
|
||||
);
|
||||
} finally {
|
||||
try {
|
||||
if (await source.exists()) await source.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(source);
|
||||
}
|
||||
} catch (_) {
|
||||
newCoverPath = null;
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:spotiflac_android/services/history_database.dart';
|
||||
import 'package:spotiflac_android/services/platform_bridge.dart';
|
||||
import 'package:spotiflac_android/services/sqlite_native_snapshot.dart';
|
||||
import 'package:spotiflac_android/services/user_profile_store.dart';
|
||||
import 'package:spotiflac_android/utils/file_access.dart';
|
||||
import 'package:spotiflac_android/utils/logger.dart';
|
||||
|
||||
typedef BackupHistoryPageLoader =
|
||||
@@ -343,9 +344,7 @@ class BackupService {
|
||||
try {
|
||||
if (await staging.exists()) await staging.delete(recursive: true);
|
||||
} catch (_) {}
|
||||
try {
|
||||
if (await partFile.exists()) await partFile.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(partFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1046,9 +1046,7 @@ class DownloadedEmbeddedCoverResolver {
|
||||
}
|
||||
|
||||
static Future<void> _deleteFileIfPresent(File file) async {
|
||||
try {
|
||||
if (await file.exists()) await file.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(file);
|
||||
}
|
||||
|
||||
static Future<void> _clearDirectoryContents(Directory directory) async {
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:spotiflac_android/services/ffmpeg_service.dart';
|
||||
import 'package:spotiflac_android/services/motion_artwork_download.dart';
|
||||
import 'package:spotiflac_android/services/motion_artwork_proxy.dart';
|
||||
import 'package:spotiflac_android/utils/file_access.dart';
|
||||
import 'package:spotiflac_android/utils/logger.dart';
|
||||
import 'package:spotiflac_android/utils/string_utils.dart';
|
||||
|
||||
@@ -171,9 +172,7 @@ class MotionArtworkStore {
|
||||
return null;
|
||||
} finally {
|
||||
for (final file in [temporary, infoTemporary]) {
|
||||
try {
|
||||
if (file != null && await file.exists()) await file.delete();
|
||||
} catch (_) {}
|
||||
if (file != null) await deleteFileQuietly(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:spotiflac_android/services/download_request_payload.dart';
|
||||
import 'package:spotiflac_android/utils/audio_format_utils.dart';
|
||||
import 'package:spotiflac_android/utils/file_access.dart';
|
||||
import 'package:spotiflac_android/utils/logger.dart';
|
||||
|
||||
part 'platform_bridge/bridge_codec.dart';
|
||||
@@ -1558,12 +1559,7 @@ class PlatformBridge {
|
||||
}
|
||||
|
||||
static Future<void> _deleteFileIfExists(String path) async {
|
||||
try {
|
||||
final file = File(path);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(File(path));
|
||||
}
|
||||
|
||||
static Future<Directory> _nativeWorkerPayloadDir() async {
|
||||
|
||||
@@ -27,13 +27,8 @@ class LibraryScanNDJSONFile {
|
||||
}
|
||||
|
||||
Future<void> delete() async {
|
||||
try {
|
||||
if (await file.exists()) await file.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(file);
|
||||
// Remove the resumable scan checkpoint after ingestion.
|
||||
try {
|
||||
final checkpoint = File('${file.path}.state');
|
||||
if (await checkpoint.exists()) await checkpoint.delete();
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(File('${file.path}.state'));
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,13 @@ import 'dart:io';
|
||||
import 'package:spotiflac_android/services/ffmpeg_service.dart';
|
||||
import 'package:spotiflac_android/services/library_database.dart';
|
||||
import 'package:spotiflac_android/services/platform_bridge.dart';
|
||||
import 'package:spotiflac_android/utils/file_access.dart';
|
||||
import 'package:spotiflac_android/utils/lyrics_metadata_helper.dart';
|
||||
|
||||
bool _hasValue(String? value) => value != null && value.trim().isNotEmpty;
|
||||
|
||||
Future<void> _safeDeleteFile(String path) async {
|
||||
try {
|
||||
final file = File(path);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
} catch (_) {}
|
||||
await deleteFileQuietly(File(path));
|
||||
}
|
||||
|
||||
Future<void> _cleanupTempFileAndParent(String path) async {
|
||||
|
||||
@@ -249,6 +249,13 @@ class FileAccessStat {
|
||||
const FileAccessStat({this.size, this.modified});
|
||||
}
|
||||
|
||||
/// Deletes [file] when it exists and swallows any error.
|
||||
Future<void> deleteFileQuietly(File file) async {
|
||||
try {
|
||||
if (await file.exists()) await file.delete();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
bool isContentUri(String? path) {
|
||||
return path != null && path.startsWith('content://');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user