winpr/clipboard: Also save lastWriteTime for FILEDESCRIPTORW
Currently, when a local uri-list is converted into a FILEDESCRIPTORW
list, WinPR doesn't submit the last write time for each file.
The result of this is that the last write time of each file on the
other peer will have the current time and not the actual last write
time that is present on the peer, where the files were copied from.
Fix this by also writing the last write time in addition to the
FD_WRITESTIME flag.
(cherry picked from commit 9ba614a1e3
)
This commit is contained in:
parent
9d8d5e5969
commit
a864f0a529
@ -22,6 +22,7 @@
|
||||
#endif
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define WIN32_FILETIME_TO_UNIX_EPOCH UINT64_C(11644473600)
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
@ -52,6 +53,7 @@ struct posix_file
|
||||
char* local_name;
|
||||
WCHAR* remote_name;
|
||||
BOOL is_directory;
|
||||
UINT64 last_write_time;
|
||||
|
||||
int fd;
|
||||
INT64 offset;
|
||||
@ -83,6 +85,7 @@ static struct posix_file* make_posix_file(const char* local_name, const WCHAR* r
|
||||
}
|
||||
|
||||
file->is_directory = S_ISDIR(statbuf.st_mode);
|
||||
file->last_write_time = (statbuf.st_mtime + WIN32_FILETIME_TO_UNIX_EPOCH) * 10 * 1000 * 1000;
|
||||
file->size = statbuf.st_size;
|
||||
return file;
|
||||
error:
|
||||
@ -496,10 +499,10 @@ static BOOL process_uri_list(const char* data, size_t length, wArrayList* files)
|
||||
}
|
||||
|
||||
static BOOL convert_local_file_to_filedescriptor(const struct posix_file* file,
|
||||
FILEDESCRIPTOR* descriptor)
|
||||
FILEDESCRIPTORW* descriptor)
|
||||
{
|
||||
size_t remote_len = 0;
|
||||
descriptor->dwFlags = FD_ATTRIBUTES | FD_FILESIZE | FD_SHOWPROGRESSUI;
|
||||
descriptor->dwFlags = FD_ATTRIBUTES | FD_FILESIZE | FD_WRITESTIME | FD_SHOWPROGRESSUI;
|
||||
|
||||
if (file->is_directory)
|
||||
{
|
||||
@ -513,6 +516,8 @@ static BOOL convert_local_file_to_filedescriptor(const struct posix_file* file,
|
||||
descriptor->nFileSizeLow = (file->size >> 0) & 0xFFFFFFFF;
|
||||
descriptor->nFileSizeHigh = (file->size >> 32) & 0xFFFFFFFF;
|
||||
}
|
||||
descriptor->ftLastWriteTime.dwLowDateTime = (file->last_write_time >> 0) & 0xFFFFFFFF;
|
||||
descriptor->ftLastWriteTime.dwHighDateTime = (file->last_write_time >> 32) & 0xFFFFFFFF;
|
||||
|
||||
remote_len = _wcslen(file->remote_name);
|
||||
|
||||
@ -526,11 +531,11 @@ static BOOL convert_local_file_to_filedescriptor(const struct posix_file* file,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static FILEDESCRIPTOR* convert_local_file_list_to_filedescriptors(wArrayList* files)
|
||||
static FILEDESCRIPTORW* convert_local_file_list_to_filedescriptors(wArrayList* files)
|
||||
{
|
||||
int i;
|
||||
int count = 0;
|
||||
FILEDESCRIPTOR* descriptors = NULL;
|
||||
FILEDESCRIPTORW* descriptors = NULL;
|
||||
count = ArrayList_Count(files);
|
||||
descriptors = calloc(count, sizeof(descriptors[0]));
|
||||
|
||||
@ -554,7 +559,7 @@ error:
|
||||
static void* convert_uri_list_to_filedescriptors(wClipboard* clipboard, UINT32 formatId,
|
||||
const void* data, UINT32* pSize)
|
||||
{
|
||||
FILEDESCRIPTOR* descriptors = NULL;
|
||||
FILEDESCRIPTORW* descriptors = NULL;
|
||||
|
||||
if (!clipboard || !data || !pSize)
|
||||
return NULL;
|
||||
@ -570,7 +575,7 @@ static void* convert_uri_list_to_filedescriptors(wClipboard* clipboard, UINT32 f
|
||||
if (!descriptors)
|
||||
return NULL;
|
||||
|
||||
*pSize = ArrayList_Count(clipboard->localFiles) * sizeof(FILEDESCRIPTOR);
|
||||
*pSize = ArrayList_Count(clipboard->localFiles) * sizeof(FILEDESCRIPTORW);
|
||||
clipboard->fileListSequenceNumber = clipboard->sequenceNumber;
|
||||
return descriptors;
|
||||
}
|
||||
@ -578,7 +583,7 @@ static void* convert_uri_list_to_filedescriptors(wClipboard* clipboard, UINT32 f
|
||||
static void* convert_filedescriptors_to_uri_list(wClipboard* clipboard, UINT32 formatId,
|
||||
const void* data, UINT32* pSize)
|
||||
{
|
||||
const FILEDESCRIPTOR* descriptors;
|
||||
const FILEDESCRIPTORW* descriptors;
|
||||
UINT32 nrDescriptors = 0;
|
||||
size_t count, x, alloc, pos, baseLength = 0;
|
||||
const char* src = (const char*)data;
|
||||
@ -600,12 +605,12 @@ static void* convert_filedescriptors_to_uri_list(wClipboard* clipboard, UINT32 f
|
||||
nrDescriptors = (UINT32)(src[3] << 24) | (UINT32)(src[2] << 16) | (UINT32)(src[1] << 8) |
|
||||
(src[0] & 0xFF);
|
||||
|
||||
count = (*pSize - 4) / sizeof(FILEDESCRIPTOR);
|
||||
count = (*pSize - 4) / sizeof(FILEDESCRIPTORW);
|
||||
|
||||
if ((count < 1) || (count != nrDescriptors))
|
||||
return NULL;
|
||||
|
||||
descriptors = (const FILEDESCRIPTOR*)&src[4];
|
||||
descriptors = (const FILEDESCRIPTORW*)&src[4];
|
||||
|
||||
if (formatId != ClipboardGetFormatId(clipboard, "FileGroupDescriptorW"))
|
||||
return NULL;
|
||||
@ -628,7 +633,7 @@ static void* convert_filedescriptors_to_uri_list(wClipboard* clipboard, UINT32 f
|
||||
for (x = 0; x < count; x++)
|
||||
{
|
||||
int rc;
|
||||
const FILEDESCRIPTOR* cur = &descriptors[x];
|
||||
const FILEDESCRIPTORW* cur = &descriptors[x];
|
||||
size_t curLen = _wcsnlen(cur->cFileName, ARRAYSIZE(cur->cFileName));
|
||||
char* curName = NULL;
|
||||
rc = ConvertFromUnicode(CP_UTF8, 0, cur->cFileName, (int)curLen, &curName, 0, NULL, NULL);
|
||||
@ -659,6 +664,7 @@ static void* convert_filedescriptors_to_uri_list(wClipboard* clipboard, UINT32 f
|
||||
|
||||
static BOOL register_file_formats_and_synthesizers(wClipboard* clipboard)
|
||||
{
|
||||
wObject* obj;
|
||||
UINT32 file_group_format_id;
|
||||
UINT32 local_file_format_id;
|
||||
file_group_format_id = ClipboardRegisterFormat(clipboard, "FileGroupDescriptorW");
|
||||
@ -672,7 +678,10 @@ static BOOL register_file_formats_and_synthesizers(wClipboard* clipboard)
|
||||
if (!clipboard->localFiles)
|
||||
goto error;
|
||||
|
||||
ArrayList_Object(clipboard->localFiles)->fnObjectFree = free_posix_file;
|
||||
obj = ArrayList_Object(clipboard->localFiles);
|
||||
if (!obj)
|
||||
goto error;
|
||||
obj->fnObjectFree = free_posix_file;
|
||||
|
||||
if (!ClipboardRegisterSynthesizer(clipboard, local_file_format_id, file_group_format_id,
|
||||
convert_uri_list_to_filedescriptors))
|
||||
|
Loading…
Reference in New Issue
Block a user