Merge "Set the file timestamp using the device info."
diff --git a/src/libmtp.c b/src/libmtp.c
index eb73e1e..b8dc50e 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -4716,6 +4716,7 @@
void const * const data)
{
int fd = -1;
+ struct utimbuf mtime;
int ret;
// Sanity check
@@ -4738,7 +4739,7 @@
return -1;
}
- ret = LIBMTP_Get_File_To_File_Descriptor(device, id, fd, callback, data);
+ ret = LIBMTP_Get_File_To_File_Descriptor(device, id, fd, callback, data, &mtime);
// Close file
close(fd);
@@ -4746,8 +4747,9 @@
// Delete partial file.
if (ret == -1) {
unlink(path);
+ } else {
+ utime(path, &mtime);
}
-
return ret;
}
@@ -4767,15 +4769,18 @@
* the <code>progress</code> function in order to
* pass along some user defined data to the progress
* updates. If not used, set this to NULL.
+ * @param mtime out parameter to return the timestamp for file on
+ * the device.
* @return 0 if the transfer was successful, any other value means
- * failure.
+ * failure.
* @see LIBMTP_Get_File_To_File()
*/
int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device,
uint32_t const id,
int const fd,
LIBMTP_progressfunc_t const callback,
- void const * const data)
+ void const * const data,
+ struct utimbuf * mtime)
{
uint16_t ret;
PTPParams *params = (PTPParams *) device->params;
@@ -4792,6 +4797,11 @@
return -1;
}
+ if (mtime != NULL) {
+ mtime->actime = ob->oi.CaptureDate;
+ mtime->modtime = ob->oi.ModificationDate;
+ }
+
// Callbacks
ptp_usb->callback_active = 1;
ptp_usb->current_transfer_total = ob->oi.ObjectCompressedSize+
@@ -4930,6 +4940,8 @@
* the <code>progress</code> function in order to
* pass along some user defined data to the progress
* updates. If not used, set this to NULL.
+ * @param mtime out parameter to return the timestamp for file on
+ * the device.
* @return 0 if the transfer was successful, any other value means
* failure.
* @see LIBMTP_Get_Track_To_File()
@@ -4938,10 +4950,11 @@
uint32_t const id,
int const fd,
LIBMTP_progressfunc_t const callback,
- void const * const data)
+ void const * const data,
+ struct utimbuf * mtime)
{
// This is just a wrapper
- return LIBMTP_Get_File_To_File_Descriptor(device, id, fd, callback, data);
+ return LIBMTP_Get_File_To_File_Descriptor(device, id, fd, callback, data, mtime);
}
/**
diff --git a/src/libmtp.h b/src/libmtp.h
index 7657ad3..aebf0ae 100644
--- a/src/libmtp.h
+++ b/src/libmtp.h
@@ -55,6 +55,7 @@
#include <stdio.h>
#include <usb.h>
#include <stdint.h>
+#include <utime.h>
/**
* @defgroup types libmtp global type definitions
@@ -818,7 +819,7 @@
int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
LIBMTP_progressfunc_t const, void const * const);
int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
- LIBMTP_progressfunc_t const, void const * const);
+ LIBMTP_progressfunc_t const, void const * const, struct utimbuf * mtime);
int LIBMTP_Get_File_To_Handler(LIBMTP_mtpdevice_t *, uint32_t const, MTPDataPutFunc, void *,
LIBMTP_progressfunc_t const, void const * const);
int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *, char const * const,
@@ -860,7 +861,7 @@
int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
LIBMTP_progressfunc_t const, void const * const);
int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
- LIBMTP_progressfunc_t const, void const * const);
+ LIBMTP_progressfunc_t const, void const * const, struct utimbuf * mtime);
int LIBMTP_Get_Track_To_Handler(LIBMTP_mtpdevice_t *, uint32_t const, MTPDataPutFunc,
void *, LIBMTP_progressfunc_t const, void const * const);
int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *,
diff --git a/src/playlist-spl.c b/src/playlist-spl.c
index 95844d0..fe5e598 100644
--- a/src/playlist-spl.c
+++ b/src/playlist-spl.c
@@ -141,7 +141,7 @@
// make sure the file will be deleted afterwards
if(unlink(tmpname) < 0)
printf("failed to delete temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
- int ret = LIBMTP_Get_File_To_File_Descriptor(device, pl->playlist_id, fd, NULL, NULL);
+ int ret = LIBMTP_Get_File_To_File_Descriptor(device, pl->playlist_id, fd, NULL, NULL, NULL);
if( ret < 0 ) {
// FIXME add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Playlist: Could not get .spl playlist file.");
close(fd);