mirror of https://github.com/FreeRDP/FreeRDP
Merge pull request #3163 from akallabeth/set_file_time
Implemented SetFileTime
This commit is contained in:
commit
857c37393b
|
@ -80,6 +80,7 @@ fi
|
||||||
common_run mkdir -p $BUILD_SRC
|
common_run mkdir -p $BUILD_SRC
|
||||||
|
|
||||||
CMAKE_CMD_ARGS="-DANDROID_NDK=$ANDROID_NDK \
|
CMAKE_CMD_ARGS="-DANDROID_NDK=$ANDROID_NDK \
|
||||||
|
-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} \
|
||||||
-DCMAKE_TOOLCHAIN_FILE=$SRC_DIR/cmake/AndroidToolchain.cmake \
|
-DCMAKE_TOOLCHAIN_FILE=$SRC_DIR/cmake/AndroidToolchain.cmake \
|
||||||
-DCMAKE_INSTALL_PREFIX=$BUILD_DST \
|
-DCMAKE_INSTALL_PREFIX=$BUILD_DST \
|
||||||
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
|
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
|
SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
|
||||||
SCRIPT_PATH=$(realpath "$SCRIPT_PATH")
|
SCRIPT_PATH=$(realpath "$SCRIPT_PATH")
|
||||||
|
|
||||||
WITH_JPEG=1
|
WITH_JPEG=0
|
||||||
WITH_OPENH264=1
|
WITH_OPENH264=1
|
||||||
WITH_OPENSSL=1
|
WITH_OPENSSL=1
|
||||||
BUILD_DEPS=1
|
BUILD_DEPS=1
|
||||||
|
ANDROID_NATIVE_API_LEVEL=android-12
|
||||||
|
|
||||||
JPEG_TAG=master
|
JPEG_TAG=master
|
||||||
OPENH264_TAG=v1.5.0
|
OPENH264_TAG=v1.5.0
|
||||||
|
|
|
@ -288,6 +288,9 @@ WINPR_API BOOL UnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffse
|
||||||
WINPR_API BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
|
WINPR_API BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
|
||||||
DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped);
|
DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped);
|
||||||
|
|
||||||
|
WINPR_API BOOL SetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
|
||||||
|
const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime);
|
||||||
|
|
||||||
WINPR_API HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
|
WINPR_API HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
|
||||||
WINPR_API HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
|
WINPR_API HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
static BOOL FileIsHandled(HANDLE handle)
|
static BOOL FileIsHandled(HANDLE handle)
|
||||||
{
|
{
|
||||||
|
@ -346,6 +348,113 @@ static BOOL FileUnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfByte
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL FileSetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
|
||||||
|
const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
#if defined(__APPLE__) || defined(ANDROID)
|
||||||
|
struct stat buf;
|
||||||
|
#endif
|
||||||
|
#ifdef ANDROID
|
||||||
|
struct timeval timevals[2];
|
||||||
|
#else
|
||||||
|
struct timespec times[2]; /* last access, last modification */
|
||||||
|
#endif
|
||||||
|
WINPR_FILE* pFile = (WINPR_FILE*)hFile;
|
||||||
|
const UINT64 EPOCH_DIFF = 11644473600ULL;
|
||||||
|
|
||||||
|
if (!hFile)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
#if defined(__APPLE__) || defined(ANDROID)
|
||||||
|
rc = fstat(fileno(pFile->fp), &buf);
|
||||||
|
if (rc < 0)
|
||||||
|
return FALSE;
|
||||||
|
#endif
|
||||||
|
if (!lpLastAccessTime)
|
||||||
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
|
||||||
|
times[0] = buf.st_atimespec;
|
||||||
|
#else
|
||||||
|
times[0].tv_sec = buf.st_atime;
|
||||||
|
times[0].tv_nsec = buf.st_atimensec;
|
||||||
|
#endif
|
||||||
|
#elif ANDROID
|
||||||
|
timevals[0].tv_sec = buf.st_mtime;
|
||||||
|
timevals[0].tv_usec = buf.st_mtimensec / 1000UL;
|
||||||
|
#else
|
||||||
|
times[0].tv_sec = UTIME_OMIT;
|
||||||
|
times[0].tv_nsec = UTIME_OMIT;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UINT64 tmp = ((UINT64)lpLastAccessTime->dwHighDateTime) << 32
|
||||||
|
| lpLastAccessTime->dwLowDateTime;
|
||||||
|
tmp -= EPOCH_DIFF;
|
||||||
|
tmp /= 10ULL;
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
tmp /= 10000ULL;
|
||||||
|
|
||||||
|
timevals[0].tv_sec = tmp / 10000ULL;
|
||||||
|
timevals[0].tv_usec = tmp % 10000ULL;
|
||||||
|
#else
|
||||||
|
times[0].tv_sec = tmp / 10000000ULL;
|
||||||
|
times[0].tv_nsec = tmp % 10000000ULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (!lpLastWriteTime)
|
||||||
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
|
||||||
|
times[1] = buf.st_mtimespec;
|
||||||
|
#else
|
||||||
|
times[1].tv_sec = buf.st_mtime;
|
||||||
|
times[1].tv_nsec = buf.st_mtimensec;
|
||||||
|
#endif
|
||||||
|
#elif ANDROID
|
||||||
|
timevals[1].tv_sec = buf.st_mtime;
|
||||||
|
timevals[1].tv_usec = buf.st_mtimensec / 1000UL;
|
||||||
|
#else
|
||||||
|
times[1].tv_sec = UTIME_OMIT;
|
||||||
|
times[1].tv_nsec = UTIME_OMIT;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UINT64 tmp = ((UINT64)lpLastWriteTime->dwHighDateTime) << 32
|
||||||
|
| lpLastWriteTime->dwLowDateTime;
|
||||||
|
tmp -= EPOCH_DIFF;
|
||||||
|
tmp /= 10ULL;
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
tmp /= 10000ULL;
|
||||||
|
|
||||||
|
timevals[1].tv_sec = tmp / 10000ULL;
|
||||||
|
timevals[1].tv_usec = tmp % 10000ULL;
|
||||||
|
#else
|
||||||
|
times[1].tv_sec = tmp / 10000000ULL;
|
||||||
|
times[1].tv_nsec = tmp % 10000000ULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Creation time can not be handled!
|
||||||
|
#ifdef __APPLE__
|
||||||
|
rc = futimes(fileno(pFile->fp), times);
|
||||||
|
#elif ANDROID
|
||||||
|
rc = utimes(pFile->lpFileName, timevals);
|
||||||
|
#else
|
||||||
|
rc = futimens(fileno(pFile->fp), times);
|
||||||
|
#endif
|
||||||
|
if (rc != 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static HANDLE_OPS fileOps = {
|
static HANDLE_OPS fileOps = {
|
||||||
FileIsHandled,
|
FileIsHandled,
|
||||||
FileCloseHandle,
|
FileCloseHandle,
|
||||||
|
@ -365,7 +474,8 @@ static HANDLE_OPS fileOps = {
|
||||||
NULL, /* FileLockFile */
|
NULL, /* FileLockFile */
|
||||||
FileLockFileEx,
|
FileLockFileEx,
|
||||||
FileUnlockFile,
|
FileUnlockFile,
|
||||||
FileUnlockFileEx
|
FileUnlockFileEx,
|
||||||
|
FileSetFileTime
|
||||||
};
|
};
|
||||||
|
|
||||||
static HANDLE_OPS shmOps = {
|
static HANDLE_OPS shmOps = {
|
||||||
|
@ -387,8 +497,8 @@ static HANDLE_OPS shmOps = {
|
||||||
NULL, /* FileLockFile */
|
NULL, /* FileLockFile */
|
||||||
NULL, /* FileLockFileEx */
|
NULL, /* FileLockFileEx */
|
||||||
NULL, /* FileUnlockFile */
|
NULL, /* FileUnlockFile */
|
||||||
NULL /* FileUnlockFileEx */
|
NULL, /* FileUnlockFileEx */
|
||||||
|
NULL /* FileSetFileTime */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -623,6 +623,27 @@ BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLo
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL WINAPI SetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
|
||||||
|
const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
|
||||||
|
{
|
||||||
|
ULONG Type;
|
||||||
|
WINPR_HANDLE *handle;
|
||||||
|
|
||||||
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
handle = (WINPR_HANDLE *)hFile;
|
||||||
|
if (handle->ops->SetFileTime)
|
||||||
|
return handle->ops->SetFileTime(handle, lpCreationTime,
|
||||||
|
lpLastAccessTime, lpLastWriteTime);
|
||||||
|
|
||||||
|
WLog_ERR(TAG, "%s operation not implemented", __FUNCTION__);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
struct _WIN32_FILE_SEARCH
|
struct _WIN32_FILE_SEARCH
|
||||||
{
|
{
|
||||||
DIR* pDir;
|
DIR* pDir;
|
||||||
|
|
|
@ -51,14 +51,14 @@ static HANDLE_CREATOR _NamedPipeClientHandleCreator;
|
||||||
|
|
||||||
static BOOL NamedPipeClientIsHandled(HANDLE handle)
|
static BOOL NamedPipeClientIsHandled(HANDLE handle)
|
||||||
{
|
{
|
||||||
WINPR_NAMED_PIPE* pFile = (WINPR_NAMED_PIPE*) handle;
|
WINPR_NAMED_PIPE* pFile = (WINPR_NAMED_PIPE*) handle;
|
||||||
|
|
||||||
if (!pFile || (pFile->Type != HANDLE_TYPE_NAMED_PIPE) || (pFile == INVALID_HANDLE_VALUE))
|
if (!pFile || (pFile->Type != HANDLE_TYPE_NAMED_PIPE) || (pFile == INVALID_HANDLE_VALUE))
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL NamedPipeClientCloseHandle(HANDLE handle)
|
BOOL NamedPipeClientCloseHandle(HANDLE handle)
|
||||||
|
@ -124,7 +124,8 @@ static HANDLE_OPS ops = {
|
||||||
NULL, /* FileLockFile */
|
NULL, /* FileLockFile */
|
||||||
NULL, /* FileLockFileEx */
|
NULL, /* FileLockFileEx */
|
||||||
NULL, /* FileUnlockFile */
|
NULL, /* FileUnlockFile */
|
||||||
NULL /* FileUnlockFileEx */
|
NULL, /* FileUnlockFileEx */
|
||||||
|
NULL /* SetFileTime */
|
||||||
};
|
};
|
||||||
|
|
||||||
static HANDLE NamedPipeClientCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
static HANDLE NamedPipeClientCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||||
|
|
|
@ -77,6 +77,8 @@ typedef BOOL (*pcUnlockFile)(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOf
|
||||||
DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh);
|
DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh);
|
||||||
typedef BOOL (*pcUnlockFileEx)(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
|
typedef BOOL (*pcUnlockFileEx)(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
|
||||||
DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped);
|
DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped);
|
||||||
|
typedef BOOL (*pcSetFileTime)(HANDLE hFile, const FILETIME *lpCreationTime,
|
||||||
|
const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime);
|
||||||
|
|
||||||
typedef struct _HANDLE_OPS
|
typedef struct _HANDLE_OPS
|
||||||
{
|
{
|
||||||
|
@ -99,6 +101,7 @@ typedef struct _HANDLE_OPS
|
||||||
pcLockFileEx LockFileEx;
|
pcLockFileEx LockFileEx;
|
||||||
pcUnlockFile UnlockFile;
|
pcUnlockFile UnlockFile;
|
||||||
pcUnlockFileEx UnlockFileEx;
|
pcUnlockFileEx UnlockFileEx;
|
||||||
|
pcSetFileTime SetFileTime;
|
||||||
} HANDLE_OPS;
|
} HANDLE_OPS;
|
||||||
|
|
||||||
struct winpr_handle
|
struct winpr_handle
|
||||||
|
|
|
@ -191,7 +191,8 @@ static HANDLE_OPS ops = {
|
||||||
NULL, /* FileLockFile */
|
NULL, /* FileLockFile */
|
||||||
NULL, /* FileLockFileEx */
|
NULL, /* FileLockFileEx */
|
||||||
NULL, /* FileUnlockFile */
|
NULL, /* FileUnlockFile */
|
||||||
NULL /* FileUnlockFileEx */
|
NULL, /* FileUnlockFileEx */
|
||||||
|
NULL /* SetFileTime */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue