aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYavor Goulishev <yavor@google.com>2012-10-01 09:58:05 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-10-01 09:58:06 -0700
commit6f4f49e45fea0e15537701a6fbd0c43f2bdbec32 (patch)
tree58c2622189ea9002f6671f58ab3a1e6848acf93a
parentc1de2578a686fc1a0c2795f6a45159a4e20a4824 (diff)
parentbf992f9881b17ef13f0877b128001e4d001d7c56 (diff)
downloadlibmtp-6f4f49e45fea0e15537701a6fbd0c43f2bdbec32.tar.gz
Merge "Set the file timestamp using the device info."
-rw-r--r--src/libmtp.c25
-rw-r--r--src/libmtp.h5
-rw-r--r--src/playlist-spl.c2
3 files changed, 23 insertions, 9 deletions
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 @@ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
void const * const data)
{
int fd = -1;
+ struct utimbuf mtime;
int ret;
// Sanity check
@@ -4738,7 +4739,7 @@ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
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 @@ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
// Delete partial file.
if (ret == -1) {
unlink(path);
+ } else {
+ utime(path, &mtime);
}
-
return ret;
}
@@ -4767,15 +4769,18 @@ int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
* 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 @@ int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device,
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 @@ int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
* 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 @@ int LIBMTP_Get_Track_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)
{
// 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 @@ typedef unsigned __int64 uint64_t;
#include <stdio.h>
#include <usb.h>
#include <stdint.h>
+#include <utime.h>
/**
* @defgroup types libmtp global type definitions
@@ -818,7 +819,7 @@ LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const);
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 @@ LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t*, uint32_t const);
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 @@ void spl_to_playlist_t(LIBMTP_mtpdevice_t* device, PTPObjectInfo *oi,
// 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);