GUAC-1452: Append .timing to end of basename for timing file.

This commit is contained in:
Michael Jumper 2016-01-27 12:13:25 -08:00
parent d421bbc075
commit 7c7a68975b
2 changed files with 35 additions and 18 deletions

View File

@ -69,7 +69,7 @@ static int guac_terminal_typescript_open_data_file(const char* path,
/* Concatenate path and name (separated by a single slash) */ /* Concatenate path and name (separated by a single slash) */
int basename_length = snprintf(basename, int basename_length = snprintf(basename,
basename_size - GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH , basename_size - GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH,
"%s/%s", path, name); "%s/%s", path, name);
/* Abort if maximum length reached */ /* Abort if maximum length reached */
@ -84,21 +84,26 @@ static int guac_terminal_typescript_open_data_file(const char* path,
O_CREAT | O_EXCL | O_WRONLY, O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
/* Prepare basename for additional suffix */ /* Continuously retry with alternate names on failure */
basename[basename_length] = '.'; if (data_fd == -1) {
char* suffix = basename + basename_length + 1;
/* Continue retrying alternative suffixes if file already exists */ /* Prepare basename for additional suffix */
for (i = 1; data_fd == -1 && errno == EEXIST basename[basename_length] = '.';
&& i <= GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX; i++) { char* suffix = &(basename[basename_length + 1]);
/* Append new suffix */ /* Continue retrying alternative suffixes if file already exists */
sprintf(suffix, "%i", i); for (i = 1; data_fd == -1 && errno == EEXIST
&& i <= GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX; i++) {
/* Retry with newly-suffixed filename */ /* Append new suffix */
data_fd = open(basename, sprintf(suffix, "%i", i);
O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR); /* Retry with newly-suffixed filename */
data_fd = open(basename,
O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR);
}
} }
@ -110,6 +115,7 @@ guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path,
const char* name, int create_path) { const char* name, int create_path) {
char basename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH]; char basename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
char timing_name[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
guac_terminal_typescript* typescript; guac_terminal_typescript* typescript;
int data_fd, timing_fd; int data_fd, timing_fd;
@ -119,13 +125,17 @@ guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path,
return NULL; return NULL;
/* Attempt to open typescript data file */ /* Attempt to open typescript data file */
data_fd = guac_terminal_typescript_open_data_file(path, name, data_fd = guac_terminal_typescript_open_data_file(path, name, basename,
basename, sizeof(basename)); sizeof(basename) - sizeof(GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX));
if (data_fd == -1) if (data_fd == -1)
return NULL; return NULL;
/* Append suffix to basename */
sprintf(timing_name, "%s.%s", basename,
GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX);
/* Attempt to open typescript timing file */ /* Attempt to open typescript timing file */
timing_fd = open("/tmp/typescript-timing", timing_fd = open(timing_name,
O_CREAT | O_EXCL | O_WRONLY, O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR); S_IRUSR | S_IWUSR);
if (timing_fd == -1) { if (timing_fd == -1) {

View File

@ -56,16 +56,23 @@
/** /**
* The maximum length of the string containing a sequential numeric suffix * The maximum length of the string containing a sequential numeric suffix
* between 1 and GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX inclusive, in bytes. * between 1 and GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX inclusive, in bytes,
* including NULL terminator.
*/ */
#define GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH 4 #define GUAC_TERMINAL_TYPESCRIPT_MAX_SUFFIX_LENGTH 4
/** /**
* The maximum overall length of the full path to the typescript file, * The maximum overall length of the full path to the typescript file,
* including any additional suffix, in bytes. * including any additional suffix and NULL terminator, in bytes.
*/ */
#define GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH 2048 #define GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH 2048
/**
* The suffix which will be appended to the typescript data file's name to
* produce the name of the timing file.
*/
#define GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX "timing"
/** /**
* An active typescript, consisting of a data file (raw terminal output) and * An active typescript, consisting of a data file (raw terminal output) and
* timing file (related timestamps and byte counts). * timing file (related timestamps and byte counts).