/// <privilege>http://tizen.org/privilege/content.write</privilege>
/// <param name="mediaId">The media ID to delete.</param>
/// <returns>true if the matched record was found and deleted, otherwise false.</returns>
- /// <remarks>The <see cref="MediaDatabase.ScanFile(string)"/> or the <see cref="MediaDatabase.ScanFolderAsync(string)"/> can be used instead.</remarks>
- /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
+ /// <remarks>
+ /// The <see cref="MediaDatabase.ScanFile(string)"/> or the <see cref="MediaDatabase.ScanFolderAsync(string)"/> can be used instead.<br/>
+ /// Since API level 6, If file still exists in file system before calling this method,
+ /// <see cref="InvalidOperationException"/> will be thrown to keep db consistency.
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">
+ /// The <see cref="MediaDatabase"/> is disconnected.<br/>
+ /// -or-<br/>
+ /// File still exists in file system. (Since API level 6)
+ /// </exception>
/// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
/// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
/// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null.</exception>
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;
}