Skip to content

Instantly share code, notes, and snippets.

@glucero
Last active August 29, 2015 14:05
Show Gist options
  • Save glucero/bad99a86781633cec548 to your computer and use it in GitHub Desktop.
Save glucero/bad99a86781633cec548 to your computer and use it in GitHub Desktop.
diff --git a/server.c b/server.c
index db172e3..a16e2eb 100644
--- a/server.c
+++ b/server.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <syslog.h>
#include <sys/time.h>
+#include <time.h>
#include <unistd.h>
#if !defined(__DARWIN_C_LEVEL)
@@ -15,6 +16,7 @@
#include "data_file_input.h"
#include "data_file_output.h"
#include "directory.h"
+#include "path.h"
#include "purge.h"
#include "server.h"
#include "util.h"
@@ -313,6 +315,10 @@ void handle_get_request(const data_store_request_t *request, const int connectio
// to disk.
//
void handle_put_request(const data_store_request_t *request, const int connection) {
+ struct tm *record_time = NULL;
+ int year = 0;
+ char *uuid_directory = NULL;
+
data_store_response_t response;
data_file_record_t record;
directory_lock_t *lock = NULL;
@@ -325,7 +331,11 @@ void handle_put_request(const data_store_request_t *request, const int connectio
record.time = request->var1.record_time;
record.value = request->var2.record_value;
- if ((lock = lock_directory(directory)) == NULL) {
+ record_time = int_to_tm(record.time);
+ year = record_time->tm_year + 1900;
+ uuid_directory = generate_data_file_directory(directory, year, request->uuid);
+
+ if ((lock = lock_directory(uuid_directory)) == NULL) {
syslog(LOG_ERR, "Failed to lock directory while handling put request in %s on line %d.\n", __FILE__, __LINE__ - 1);
} else {
if (write_record(directory, &record, request->uuid, config_max_days_per_file()) == -1) {
@@ -344,7 +354,11 @@ void handle_put_request(const data_store_request_t *request, const int connectio
break;
}
- if ((lock = lock_directory(directory)) == NULL) {
+ record_time = int_to_tm(record.time);
+ year = record_time->tm_year + 1900;
+ uuid_directory = generate_data_file_directory(directory, year, request->uuid);
+
+ if ((lock = lock_directory(uuid_directory)) == NULL) {
syslog(LOG_ERR, "Failed to lock directory while handling put request in %s on line %d.\n", __FILE__, __LINE__ - 1);
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment