Skip to content

Commit

Permalink
ptp2/lib: add a check when deleting files
Browse files Browse the repository at this point in the history
libgphoto2 currently lacks error handling for failed file deletions,
potentially leading to unexpected behavior in user-space applications.

Signed-off-by: tuhaowen <[email protected]>
Signed-off-by: WangYuli <[email protected]>
  • Loading branch information
tuhaowen authored and Avenger-285714 committed Nov 19, 2024
1 parent 5c8da2d commit d7b3e27
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion camlibs/ptp2/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -9027,6 +9027,7 @@ delete_file_func (CameraFilesystem *fs, const char *folder,
const char *filename, void *data, GPContext *context)
{
Camera *camera = data;
uint32_t ret;
uint32_t storage;
PTPParams *params = &camera->pl->params;

Expand Down Expand Up @@ -9061,7 +9062,12 @@ delete_file_func (CameraFilesystem *fs, const char *folder,
handle = find_child(params, filename, storage, handle, NULL);

/* in some cases we return errors ... just ignore them for now */
LOG_ON_PTP_E (ptp_deleteobject(params, handle, 0));
ret = ptp_deleteobject(params, handle, 0);
LOG_ON_PTP_E (ret);
if (ret != PTP_RC_OK) {
printf("Could not delete object.\n");
return GP_ERROR;
}

/* On some Canon firmwares, a DeleteObject causes a ObjectRemoved event
* to be sent. At least on Digital IXUS II and PowerShot A85. But
Expand Down

0 comments on commit d7b3e27

Please sign in to comment.