Pull info from stat() during file open.

This commit is contained in:
Michael Jumper 2013-08-01 13:36:39 -07:00
parent 2f662257d9
commit 06a18f6766
2 changed files with 57 additions and 0 deletions

View File

@ -45,6 +45,10 @@
#include "compat/winpr-stream.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <guacamole/pool.h>
#include "rdpdr_messages.h"
@ -117,6 +121,7 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data;
char path_buffer[GUAC_RDPDR_FS_MAX_PATH];
struct stat file_stat;
int fd;
int file_id;
guac_rdpdr_fs_file* file;
@ -203,6 +208,29 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path,
file = &(data->files[file_id]);
file->fd = fd;
/* Attempt to pull file information */
if (fstat(fd, &file_stat) == 0) {
file->size = file_stat.st_size;
file->ctime = file_stat.st_ctime;
file->mtime = file_stat.st_mtime;
file->atime = file_stat.st_atime;
}
/* If information cannot be retrieved, fake it */
else {
guac_client_log_info(device->rdpdr->client, "Unable to read information for \"%s\"",
path_buffer);
/* Init information to 0, lacking any alternative */
file->size = 0;
file->ctime = 0;
file->mtime = 0;
file->atime = 0;
}
data->open_files++;
return file_id;

View File

@ -55,6 +55,9 @@
#include "compat/winpr-stream.h"
#endif
#include <sys/types.h>
#include <dirent.h>
#include <guacamole/pool.h>
#include "rdpdr_service.h"
@ -145,6 +148,32 @@ typedef struct guac_rdpdr_fs_file {
*/
int fd;
/**
* Associated directory stream, if any. This field only applies
* if the file is being used as a directory.
*/
DIR* dir;
/**
* The size of this file, in bytes.
*/
off_t size;
/**
* The time this file was created, as a UNIX timestamp.
*/
time_t ctime;
/**
* The time this file was last modified, as a UNIX timestamp.
*/
time_t mtime;
/**
* The time this file was last accessed, as a UNIX timestamp.
*/
time_t atime;
} guac_rdpdr_fs_file;
/**