mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2025-06-03 00:00:20 +00:00
commit
07ceeb1f91
@ -303,7 +303,9 @@ static BOOL drive_file_init(DRIVE_FILE* file)
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&messageBuffer, 0, NULL);
|
||||
WLog_ERR(TAG, "Error in drive_file_init: %s %s", messageBuffer, file->fullpath);
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath));
|
||||
WLog_ERR(TAG, "Error in drive_file_init: %s %s", messageBuffer, fullpath);
|
||||
/* Free the buffer. */
|
||||
LocalFree(messageBuffer);
|
||||
/* restore original error code */
|
||||
@ -668,8 +670,10 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
|
||||
if (file->file_handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
WLog_ERR(TAG, "Unable to set file time %s (%" PRId32 ")", file->fullpath,
|
||||
GetLastError());
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath) - 1);
|
||||
|
||||
WLog_ERR(TAG, "Unable to set file time %s (%" PRId32 ")", fullpath, GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -703,11 +707,20 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
|
||||
DEBUG_WSTR("SetFileTime %s", file->fullpath);
|
||||
|
||||
SetFileAttributesW(file->fullpath, FileAttributes);
|
||||
if (!SetFileAttributesW(file->fullpath, FileAttributes))
|
||||
{
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath));
|
||||
WLog_ERR(TAG, "Unable to set file attributes for %s", fullpath);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!SetFileTime(file->file_handle, pftCreationTime, pftLastAccessTime,
|
||||
pftLastWriteTime))
|
||||
{
|
||||
WLog_ERR(TAG, "Unable to set file time to %s", file->fullpath);
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath));
|
||||
WLog_ERR(TAG, "Unable to set file time for %s", fullpath);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -725,8 +738,10 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
|
||||
if (file->file_handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %" PRId64 " (%" PRId32 ")", file->fullpath,
|
||||
size, GetLastError());
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath));
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %" PRId64 " (%" PRId32 ")", fullpath, size,
|
||||
GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -734,8 +749,10 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
|
||||
if (!SetFilePointerEx(file->file_handle, liSize, NULL, FILE_BEGIN))
|
||||
{
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %" PRId64 " (%" PRId32 ")", file->fullpath,
|
||||
size, GetLastError());
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath));
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %" PRId64 " (%" PRId32 ")", fullpath, size,
|
||||
GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -743,8 +760,10 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
|
||||
if (SetEndOfFile(file->file_handle) == 0)
|
||||
{
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %" PRId64 " (%" PRId32 ")", file->fullpath,
|
||||
size, GetLastError());
|
||||
char fullpath[MAX_PATH] = { 0 };
|
||||
(void)ConvertWCharToUtf8(file->fullpath, fullpath, sizeof(fullpath));
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %" PRId64 " (%" PRId32 ")", fullpath, size,
|
||||
GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -174,6 +174,7 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove,
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", pFile->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return INVALID_SET_FILE_POINTER;
|
||||
}
|
||||
|
||||
@ -209,6 +210,7 @@ static BOOL FileSetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove,
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", pFile->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -307,6 +309,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh)
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return INVALID_FILE_SIZE;
|
||||
}
|
||||
|
||||
@ -315,6 +318,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh)
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "_fseeki64(%s) failed with %s [0x%08X]", file->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return INVALID_FILE_SIZE;
|
||||
}
|
||||
|
||||
@ -325,6 +329,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh)
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return INVALID_FILE_SIZE;
|
||||
}
|
||||
|
||||
@ -333,6 +338,7 @@ static DWORD FileGetFileSize(HANDLE Object, LPDWORD lpFileSizeHigh)
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "_ftelli64(%s) failed with %s [0x%08X]", file->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return INVALID_FILE_SIZE;
|
||||
}
|
||||
|
||||
@ -386,6 +392,7 @@ static BOOL FileGetFileInformationByHandle(HANDLE hFile,
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "fstat failed with %s [%#08X]", errno,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)));
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -482,6 +489,7 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, WINPR_ATTR_UNUSED DWORD
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "F_SETLK failed with %s [0x%08X]",
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
@ -498,6 +506,7 @@ static BOOL FileLockFileEx(HANDLE hFile, DWORD dwFlags, WINPR_ATTR_UNUSED DWORD
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "flock failed with %s [0x%08X]",
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
@ -536,6 +545,7 @@ static BOOL FileUnlockFile(HANDLE hFile, WINPR_ATTR_UNUSED DWORD dwFileOffsetLow
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]", pFile->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -545,6 +555,7 @@ static BOOL FileUnlockFile(HANDLE hFile, WINPR_ATTR_UNUSED DWORD dwFileOffsetLow
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [0x%08X]", pFile->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
@ -588,6 +599,7 @@ static BOOL FileUnlockFileEx(HANDLE hFile, WINPR_ATTR_UNUSED DWORD dwReserved,
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "F_UNLCK on %s failed with %s [0x%08X]", pFile->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
@ -596,6 +608,7 @@ static BOOL FileUnlockFileEx(HANDLE hFile, WINPR_ATTR_UNUSED DWORD dwReserved,
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "flock(LOCK_UN) %s failed with %s [0x%08X]", pFile->lpFileName,
|
||||
winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
@ -642,7 +655,13 @@ static BOOL FileSetFileTime(HANDLE hFile, WINPR_ATTR_UNUSED const FILETIME* lpCr
|
||||
// TODO: Creation time can not be handled!
|
||||
const int rc = futimens(fileno(pFile->fp), times);
|
||||
if (rc != 0)
|
||||
{
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "futimens failed: %s [%d]", winpr_strerror(errno, ebuffer, sizeof(ebuffer)),
|
||||
errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -687,7 +706,13 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
|
||||
|
||||
const int rc = fstat(fileno(pFile->fp), &buf);
|
||||
if (rc < 0)
|
||||
{
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "fstat failed: %s [%d]", winpr_strerror(errno, ebuffer, sizeof(ebuffer)),
|
||||
errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
struct timeval timevals[2] = { statToTimeval(&buf), statToTimeval(&buf) };
|
||||
if (lpLastAccessTime)
|
||||
@ -700,7 +725,13 @@ static BOOL FileSetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
|
||||
{
|
||||
const int res = utimes(pFile->lpFileName, timevals);
|
||||
if (res != 0)
|
||||
{
|
||||
char ebuffer[256] = { 0 };
|
||||
WLog_ERR(TAG, "utimes failed: %s [%d]", winpr_strerror(errno, ebuffer, sizeof(ebuffer)),
|
||||
errno);
|
||||
SetLastError(map_posix_err(errno));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -1012,7 +1043,12 @@ static HANDLE FileCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dw
|
||||
if (fstat(fileno(pFile->fp), &st) == 0 && dwFlagsAndAttributes & FILE_ATTRIBUTE_READONLY)
|
||||
{
|
||||
st.st_mode &= WINPR_ASSERTING_INT_CAST(mode_t, (mode_t)(~(S_IWUSR | S_IWGRP | S_IWOTH)));
|
||||
fchmod(fileno(pFile->fp), st.st_mode);
|
||||
if (fchmod(fileno(pFile->fp), st.st_mode) != 0)
|
||||
{
|
||||
SetLastError(map_posix_err(errno));
|
||||
FileCloseHandle(pFile);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
SetLastError(STATUS_SUCCESS);
|
||||
|
@ -612,9 +612,6 @@ BOOL SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
|
||||
{
|
||||
BOOL rc = FALSE;
|
||||
#ifdef WINPR_HAVE_FCNTL_H
|
||||
struct stat st = { 0 };
|
||||
int fd = 0;
|
||||
|
||||
if (dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)
|
||||
{
|
||||
char buffer[8192] = { 0 };
|
||||
@ -623,10 +620,11 @@ BOOL SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
|
||||
WLog_WARN(TAG, "Unsupported flags %s, ignoring!", flags);
|
||||
}
|
||||
|
||||
fd = open(lpFileName, O_RDONLY);
|
||||
int fd = open(lpFileName, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return FALSE;
|
||||
|
||||
struct stat st = { 0 };
|
||||
if (fstat(fd, &st) != 0)
|
||||
goto fail;
|
||||
|
||||
@ -652,20 +650,11 @@ fail:
|
||||
BOOL SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
|
||||
{
|
||||
BOOL ret = 0;
|
||||
LPSTR lpCFileName = NULL;
|
||||
|
||||
if (!lpFileName)
|
||||
return FALSE;
|
||||
|
||||
if (dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)
|
||||
{
|
||||
char buffer[8192] = { 0 };
|
||||
const char* flags =
|
||||
flagsToStr(buffer, sizeof(buffer), dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
|
||||
WLog_WARN(TAG, "Unsupported flags %s, ignoring!", flags);
|
||||
}
|
||||
|
||||
lpCFileName = ConvertWCharToUtf8Alloc(lpFileName, NULL);
|
||||
char* lpCFileName = ConvertWCharToUtf8Alloc(lpFileName, NULL);
|
||||
if (!lpCFileName)
|
||||
{
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
|
Loading…
Reference in New Issue
Block a user