`pkg-config --cflags $(PACKAGES)`
LDFLAGS=-g -pg -ltar `pkg-config --libs $(PACKAGES)`
-SRCS=scandir.cc sha1.cc store.cc tarstore.cc
+SRCS=format.cc scandir.cc sha1.cc store.cc tarstore.cc
OBJS=$(SRCS:.cc=.o)
scandir : $(OBJS)
--- /dev/null
+/* LBS: An LFS-inspired filesystem backup system
+ * Copyright (C) 2007 Michael Vrable
+ *
+ * Utility functions for converting various datatypes to text format (and
+ * later, for parsing them back, perhaps).
+ */
+
+#include <stdio.h>
+#include <uuid/uuid.h>
+
+#include <string>
+#include <sstream>
+
+using std::string;
+
+/* Perform URI-style escaping of a string. Bytes which cannot be represented
+ * directly are encoded in the form %xx (where "xx" is a string of two
+ * hexadecimal digits). */
+string uri_encode(const string &in)
+{
+ string out;
+
+ for (size_t i = 0; i < in.length(); i++) {
+ unsigned char c = in[i];
+
+ if (c > '%' && c <= 0x7f) {
+ out += c;
+ } else {
+ char buf[4];
+ sprintf(buf, "%%%02x", c);
+ out += buf;
+ }
+ }
+
+ return out;
+}
--- /dev/null
+/* LBS: An LFS-inspired filesystem backup system
+ * Copyright (C) 2006 Michael Vrable
+ *
+ * Utility functions for converting various datatypes to text format (and
+ * later, for parsing them back, perhaps).
+ */
+
+#ifndef _LBS_FORMAT_H
+#define _LBS_FORMAT_H
+
+#include <string>
+
+std::string uri_encode(const std::string &in);
+
+#endif // _LBS_TARSTORE_H
#include <iostream>
#include <sstream>
+#include "format.h"
#include "store.h"
#include "tarstore.h"
#include "sha1.h"
printf("%s\n", path.c_str());
- metadata << "name: " << path << "\n";
+ metadata << "name: " << uri_encode(path) << "\n";
metadata << "mode: " << (stat_buf.st_mode & 07777) << "\n";
metadata << "atime: " << stat_buf.st_atime << "\n";
metadata << "ctime: " << stat_buf.st_ctime << "\n";
/* LBS: An LFS-inspired filesystem backup system
- * Copyright (C) 2006 Michael Vrable
+ * Copyright (C) 2007 Michael Vrable
*
* Backup data is stored in a collection of objects, which are grouped together
* into segments for storage purposes. This implementation of the object store