Browse Source

- cleanup code

- add script which creates the directory tree for better scaling
  of mod_files

I have to decide yet whether we implement the garbage collection in the
module or if we simply let the user do

find path -ctime +1 | xargs rm
experimetnal/RETURN_REF_PATCH
Sascha Schumann 27 years ago
parent
commit
1dd31c38a6
  1. 25
      ext/session/mod_files.c
  2. 16
      ext/session/mod_files.sh

25
ext/session/mod_files.c

@ -39,12 +39,10 @@ typedef struct {
int dirdepth;
} ps_files;
ps_module ps_mod_files = {
PS_MOD(files)
};
#define PS_FILES_DATA ps_files *data = *mod_data
PS_OPEN_FUNC(files)
@ -93,8 +91,14 @@ static void _ps_files_open(ps_files *data, const char *key)
int keylen;
if(data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) {
if(data->lastkey) efree(data->lastkey);
if(data->fd > -1) close(data->fd);
if(data->lastkey) {
efree(data->lastkey);
data->lastkey = NULL;
}
if(data->fd != -1) {
close(data->fd);
data->fd = -1;
}
keylen = strlen(key);
if(keylen <= data->dirdepth || MAXPATHLEN <
@ -111,10 +115,11 @@ static void _ps_files_open(ps_files *data, const char *key)
data->lastkey = estrdup(key);
#ifdef O_EXCL
data->fd = open(buf, O_EXCL | O_RDWR | O_CREAT, 0600);
/* -1, if file exists and access failed due to O_EXCL|O_CREAT */
/* in the common case, the file already exists */
data->fd = open(buf, O_EXCL | O_RDWR);
if(data->fd == -1) {
data->fd = open(buf, O_EXCL | O_RDWR);
/* create it, if necessary */
data->fd = open(buf, O_EXCL | O_RDWR | O_CREAT, 0600);
}
#else
data->fd = open(buf, O_CREAT | O_RDWR, 0600);
@ -132,8 +137,9 @@ PS_READ_FUNC(files)
PS_FILES_DATA;
_ps_files_open(data, key);
if(data->fd < 0)
if(data->fd < 0) {
return FAILURE;
}
if(fstat(data->fd, &sbuf)) {
return FAILURE;
@ -158,8 +164,9 @@ PS_WRITE_FUNC(files)
PS_FILES_DATA;
_ps_files_open(data, key);
if(data->fd < 0)
if(data->fd < 0) {
return FAILURE;
}
ftruncate(data->fd, 0);
lseek(data->fd, 0, SEEK_SET);

16
ext/session/mod_files.sh

@ -0,0 +1,16 @@
#! /bin/sh
if test "$2" = ""; then
echo "usage: $0 basedir depth"
exit 1
fi
if test "$2" = "0"; then
exit 0
fi
for i in a b c d e f 0 1 2 3 4 5 6 7 8 9; do
newpath="$1/$i"
mkdir $newpath || exit 1
sh $0 $newpath `expr $2 - 1`
done
Loading…
Cancel
Save