+// 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;
+ }
+ }
+}
+