|
From: <mr...@mr...> - 2005-03-09 11:08:56
|
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2005/03/09 12:08:29+01:00 mr...@fo... =
# file: create missing directories in path
# =
# src/file/file.c
# 2005/03/09 12:08:29+01:00 mr...@fo... +22 -6
# create missing directories in path
# =
# src/file/TC2Module
# 2005/03/09 12:08:29+01:00 mr...@fo... +2 -0
# option create_dirs
# =
diff -Nru a/src/file/TC2Module b/src/file/TC2Module
--- a/src/file/TC2Module 2005-03-09 12:08:46 +01:00
+++ b/src/file/TC2Module 2005-03-09 12:08:47 +01:00
@@ -13,3 +13,5 @@
implement "URL/dir" "read" dir_read
implement "URL/dir" "seek" dir_seek
implement "URL/dir" "close" dir_close
+
+option create_dirs%i=3D0
diff -Nru a/src/file/file.c b/src/file/file.c
--- a/src/file/file.c 2005-03-09 12:08:46 +01:00
+++ b/src/file/file.c 2005-03-09 12:08:46 +01:00
@@ -1,5 +1,5 @@
/**
- Copyright (C) 2003 Michael Ahlberg, M=C3=A5ns Rullg=C3=A5rd
+ Copyright (C) 2003-2005 Michael Ahlberg, M=C3=A5ns Rullg=C3=A5rd
=
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
@@ -28,9 +28,11 @@
#include <stdio.h>
#include <unistd.h>
#include <alloca.h>
+#include <errno.h>
#include <tctypes.h>
#include <tcstring.h>
#include <tcalloc.h>
+#include <tcdirent.h>
#include <sys/stat.h>
#include <file_tc2.h>
=
@@ -87,8 +89,20 @@
url +=3D 5;
=
if(stat64(url, &st)){
- if(*mode =3D=3D 'r')
+ char *d, *e;
+
+ if(*mode =3D=3D 'r' && mode[1] !=3D '+')
+ return NULL;
+ if(errno !=3D ENOENT || !tc2_url_file_conf_create_dirs)
return NULL;
+
+ d =3D strdup(url);
+ e =3D strrchr(d, '/');
+ if(e > d){
+ *e =3D 0;
+ tcmkpath(d, 0777);
+ }
+ free(d);
} else if(S_ISDIR(st.st_mode)){
return dir_open(url, mode);
}
@@ -97,16 +111,18 @@
return NULL;
=
u =3D tcallocdz(sizeof(*u), NULL, file_free);
- if(strchr(mode, 'r'))
+ if(*mode =3D=3D 'r' || mode[1] =3D=3D '+'){
u->read =3D file_read;
- if(strchr(mode, 'w'))
+ u->size =3D st.st_size;
+ }
+ if(*mode =3D=3D 'w' || *mode =3D=3D 'a' || mode[1] =3D=3D '+'){
u->write =3D file_write;
+ u->size =3D 0;
+ }
u->seek =3D file_seek;
u->tell =3D file_tell;
u->close =3D file_close;
u->private =3D f;
-
- u->size =3D st.st_size;
=
return u;
}
|