#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "binary_storage.h"
#include "utils.h"
#include "fuse_xattrs_config.h"
#include "stringmem.h"
+#include "xattrs_config.h"
#include <sys/xattr.h>
debug_print("path=%s sidecar_path=%s\n", path, sidecar_path);
char *buffer = __read_file(sidecar_path, buffer_size);
- free (sidecar_path);
+ strfree (sidecar_path);
return buffer;
}
return 0;
}
+// Ensure existence of tail path from either source_dir or sidecar_dir
+static int ensure_dirs(char *path) {
+ int n = strlen( path );
+ char *p = stralloc( n+1 );
+ memcpy( p, path, n+1 );
+ char *e = p + 1;
+ if ( strncmp( path, xattrs_config.source_dir,
+ xattrs_config.source_dir_size ) == 0 ) {
+ e += xattrs_config.source_dir_size;
+ } else if ( strncmp( path, xattrs_config.sidecar_dir,
+ xattrs_config.sidecar_dir_size ) == 0 ) {
+ e += xattrs_config.sidecar_dir_size;
+ }
+ if ( e - p >= n ) {
+ return 0;
+ }
+ for ( ;; ) {
+ while ( *e && *e != '/' ) e++;
+ if ( *e ) {
+ *e = 0;
+ if ( access( p, F_OK ) && mkdir( p, 0777 ) ) {
+ return 1;
+ }
+ *(e++) = '/';
+ } else {
+ return 0;
+ }
+ }
+}
+
/**
*
* @param path - path to file.
int status;
char *sidecar_path = get_sidecar_path(path);
+
+ if ( ensure_dirs( sidecar_path ) ) {
+ return -ENOATTR;
+ }
+
FILE *file = fopen(sidecar_path, "w");
strfree(sidecar_path);