Fix minor issue
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
index 4e44550..1d1283f 100644 (file)
@@ -567,51 +567,28 @@ static int __media_svc_safe_atoi(char *buffer, int *si)
 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
+       struct statfs fs;
+       char *thumb_path = NULL;
+       long bsize_kbytes = 0;
+       GError *error = NULL;
 
+       media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
        media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
 
-       if (!image) {
-               media_svc_error("invalid image..");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       struct statfs fs;
-       char *thumb_path = NULL;
        ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
-       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
-
-       if (-1 == statfs(thumb_path, &fs)) {
-               media_svc_error("error in statfs");
-               g_free(thumb_path);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
 
+       ret = statfs(thumb_path, &fs);
        g_free(thumb_path);
+       media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
 
-       long bsize_kbytes = fs.f_bsize >> 10;
+       bsize_kbytes = fs.f_bsize >> 10;
+       media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
 
-       if ((bsize_kbytes * fs.f_bavail) < 1024) {
-               media_svc_error("not enought space...");
-               return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
-       }
-
-       FILE *fp = NULL;
-       int nwrite = -1;
-       if (image != NULL && size > 0) {
-               fp = fopen(image_path, "w");
-
-               if (fp == NULL) {
-                       media_svc_error("failed to open file");
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-
-               nwrite = fwrite(image, 1, size, fp);
-               if (nwrite != size) {
-                       media_svc_error("failed to write thumbnail");
-                       fclose(fp);
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-               fclose(fp);
+       if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
+               media_svc_error("g_file_set_contents faild:%s", error->message);
+               g_error_free(error);
+               return MS_MEDIA_ERR_INTERNAL;
        }
 
        return MS_MEDIA_ERR_NONE;