check mount status before scan directory check 11/303211/2
authorsamsung2013 <yuzhi.he@samsung.com>
Thu, 21 Dec 2023 08:29:28 +0000 (16:29 +0800)
committersamsung2013 <yuzhi.he@samsung.com>
Fri, 22 Dec 2023 07:09:27 +0000 (15:09 +0800)
Change-Id: I867eebe69cfc423ccf849815a295e7bed73122ed

src/media_content.c

index 2b66211..f9b7b8d 100644 (file)
 * limitations under the License.
 */
 
-
 #include <media_info_private.h>
 #include <media_util_private.h>
+#include <mntent.h>
+#include <tzplatform_config.h>
 
 static sqlite3 *db_handle = NULL;
 static int ref_count = 0;
@@ -389,6 +390,44 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 }
 
 #ifdef _USE_TVPD_MODE
+bool _is_mounted(const char *dir_path)
+{
+       bool ret = false;
+       char mount_path[MAX_PATH_LEN] = {0,};
+       char root_path[MAX_PATH_LEN] = {0,};
+       struct mntent *mnt;
+       const char *table = "/etc/mtab";
+       FILE *fp;
+
+       strcpy(root_path, tzplatform_getenv(TZ_SYS_STORAGE));
+       strcat(root_path, "/USBDrive");
+
+       if (!g_str_has_prefix(dir_path, root_path))
+               return true;
+
+       char *p = strstr(dir_path + strlen(root_path), "/");
+       if(p && p - dir_path < MAX_PATH_LEN)
+               strncpy(mount_path, dir_path, p - dir_path);
+       else
+               strcpy(mount_path, dir_path);
+
+       fp = setmntent(table, "r");
+       if (!fp) {
+               content_error("open /etc/mtab failed");
+               return false;
+       }
+       while ((mnt = getmntent(fp))) {
+               if (!strncmp(mnt->mnt_dir, mount_path, strlen(mount_path))) {
+                       ret = true;
+                       break;
+               }
+       }
+       endmntent(fp);
+
+       content_info("dir_path[%s] mount_path[%s] ret[%d]", dir_path, mount_path, ret);
+       return ret;
+}
+
 int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan_completed_cb_v2 callback, void *user_data)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -397,6 +436,7 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan
        content_retip_if_fail(STRING_VALID(path));
        content_retip_if_fail(callback);
 
+       content_retvm_if(!_is_mounted(path), MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "path is not mounted");
        content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
        ret = _media_content_check_dir(path);