From 90e0b41eccc7da4fe6551f15ae79ebde72d166ca Mon Sep 17 00:00:00 2001 From: hsgwon Date: Mon, 15 Apr 2019 15:32:40 +0900 Subject: [PATCH] [MediaContent] Add exception and change p/invoke function (#782) * [MediaController] Add exception and change p/invoke function --- .../MediaInfoCommand.cs | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs index 3a820bf90..b47464669 100644 --- a/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs +++ b/src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs @@ -476,8 +476,16 @@ namespace Tizen.Content.MediaContent /// http://tizen.org/privilege/content.write /// The media ID to delete. /// true if the matched record was found and deleted, otherwise false. - /// The or the can be used instead. - /// The is disconnected. + /// + /// The or the can be used instead.
+ /// Since API level 6, If file still exists in file system before calling this method, + /// will be thrown to keep db consistency. + ///
+ /// + /// The is disconnected.
+ /// -or-
+ /// File still exists in file system. (Since API level 6) + ///
/// The has already been disposed of. /// An error occurred while executing the command. /// is null. @@ -496,7 +504,21 @@ namespace Tizen.Content.MediaContent return false; } - CommandHelper.Delete(Interop.MediaInfo.Delete, mediaId); + Interop.MediaInfo.GetMediaFromDB(mediaId, out var handle). + ThrowIfError("Failed to delete MediaInfo."); + + var path = InteropHelper.GetString(handle, Interop.MediaInfo.GetFilePath); + + // If we don't check file existence before calling `ScanFile` method, + // The inconsistency between DB and file system could be occurred. + if (File.Exists(path)) + { + throw new InvalidOperationException("File still exists in file system. Remove it first."); + } + + // Native 'delete' function was deprecated, so we need to use 'scan file' function instead of it. + Database.ScanFile(path); + return true; } -- 2.34.1