Logo Search packages:      
Sourcecode: libgphoto2 version File versions  Download package

int gp_filesystem_set_info ( CameraFilesystem fs,
const char *  folder,
const char *  filename,
CameraFileInfo  info,
GPContext context 
)

gp_filesystem_set_info: : a CameraFilesystem : : : : a GPContext

Return value: a gphoto2 error code.

Definition at line 2333 of file gphoto2-filesys.c.

References _CameraFilesystem::folder, gp_filesystem_number(), _CameraFilesystem::info_data, and _CameraFilesystem::set_info_func.

{
      int x, y, result, name, e;

      CHECK_NULL (fs && folder && filename);
      CC (context);
      CA (folder, context);

      if (!fs->set_info_func) {
            gp_context_error (context, 
                  _("The filesystem doesn't support setting file "
                    "information"));
            return (GP_ERROR_NOT_SUPPORTED);
      }

      /* Search folder and file */
      CR (x = gp_filesystem_folder_number (fs, folder, context));
      CR (y = gp_filesystem_number (fs, folder, filename, context));

      /* Check if people want to set read-only attributes */
      if ((info.file.fields    & GP_FILE_INFO_TYPE)   ||
          (info.file.fields    & GP_FILE_INFO_SIZE)   ||
          (info.file.fields    & GP_FILE_INFO_WIDTH)  ||
          (info.file.fields    & GP_FILE_INFO_HEIGHT) ||
          (info.file.fields    & GP_FILE_INFO_STATUS) ||
          (info.preview.fields & GP_FILE_INFO_TYPE)   ||
          (info.preview.fields & GP_FILE_INFO_SIZE)   ||
          (info.preview.fields & GP_FILE_INFO_WIDTH)  ||
          (info.preview.fields & GP_FILE_INFO_HEIGHT) ||
          (info.preview.fields & GP_FILE_INFO_STATUS) ||
          (info.audio.fields   & GP_FILE_INFO_TYPE)   ||
          (info.audio.fields   & GP_FILE_INFO_SIZE)   ||
          (info.audio.fields   & GP_FILE_INFO_STATUS)) {
            gp_context_error (context, _("Read-only file attributes "
                  "like width and height can not be changed."));
            return (GP_ERROR_BAD_PARAMETERS);
      }

      /*
       * Set the info. If anything goes wrong, mark info as dirty, 
       * because the operation could have been partially successful.
       *
       * Handle name changes in a separate round.
       */
      name = (info.file.fields & GP_FILE_INFO_NAME);
      info.file.fields &= ~GP_FILE_INFO_NAME;
      result = fs->set_info_func (fs, folder, filename, info, fs->info_data,
                            context);
      if (result < 0) {
            fs->folder[x].file[y].info_dirty = 1;
            return (result);
      }
      if (info.file.fields & GP_FILE_INFO_PERMISSIONS)
            fs->folder[x].file[y].info.file.permissions = 
                                    info.file.permissions;

      /* Handle name change */
      if (name) {

            /* Make sure the file does not exist */
            e = gp_filesystem_number (fs, folder, info.file.name, context);
            if (e != GP_ERROR_FILE_NOT_FOUND)
                  return (e);
            
            info.preview.fields = GP_FILE_INFO_NONE;
            info.file.fields = GP_FILE_INFO_NAME;
            info.audio.fields = GP_FILE_INFO_NONE;
            CR (fs->set_info_func (fs, folder, filename, info,
                               fs->info_data, context));
            strncpy (fs->folder[x].file[y].info.file.name, info.file.name,
                   sizeof (fs->folder[x].file[y].info.file.name));
            strncpy (fs->folder[x].file[y].name, info.file.name,
                   sizeof (fs->folder[x].file[y].name));
      }

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index