shoudl in theory handle locks better....
SVN revision: 2754
This commit is contained in:
parent
102fa5c645
commit
03443b4e9e
|
@ -25,7 +25,44 @@ void formats (ImlibLoader *l);
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <db.h>
|
#include <db.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
permissions(char *file)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (!stat(file, &st) < 0)
|
||||||
|
return 0;
|
||||||
|
return st.st_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
exists(char *file)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (!stat(file, &st) < 0)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
can_read(char *file)
|
||||||
|
{
|
||||||
|
if (!(permissions(file) & (S_IRUSR | S_IRGRP | S_IROTH)))
|
||||||
|
return 0;
|
||||||
|
return (1 + access(file, R_OK));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
can_write(char *file)
|
||||||
|
{
|
||||||
|
if (!(permissions(file) & (S_IWUSR | S_IWGRP | S_IWOTH)))
|
||||||
|
return 0;
|
||||||
|
return (1 + access(file, W_OK));
|
||||||
|
}
|
||||||
|
|
||||||
char
|
char
|
||||||
load (ImlibImage *im, ImlibProgressFunction progress,
|
load (ImlibImage *im, ImlibProgressFunction progress,
|
||||||
|
@ -48,6 +85,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
|
||||||
int flen;
|
int flen;
|
||||||
|
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
|
if (!can_read(file))
|
||||||
|
return 0;
|
||||||
flen = strlen(file);
|
flen = strlen(file);
|
||||||
strcpy(key, &(ptr[1]));
|
strcpy(key, &(ptr[1]));
|
||||||
if ((flen > 3) &&
|
if ((flen > 3) &&
|
||||||
|
@ -59,8 +98,20 @@ load (ImlibImage *im, ImlibProgressFunction progress,
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
db = dbm_open(file, O_RDONLY, 0664);
|
db = dbm_open(file, O_RDONLY, 0664);
|
||||||
|
if (!db)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
usleep((rand() % 0xff) * 1000);
|
||||||
|
db = dbm_open(file, O_RDONLY, 0664);
|
||||||
|
if (db)
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!db)
|
if (!db)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
dkey.dptr = key;
|
dkey.dptr = key;
|
||||||
dkey.dsize = strlen(key);
|
dkey.dsize = strlen(key);
|
||||||
|
@ -195,6 +246,13 @@ save (ImlibImage *im, ImlibProgressFunction progress,
|
||||||
int flen;
|
int flen;
|
||||||
|
|
||||||
*cp = 0;
|
*cp = 0;
|
||||||
|
if (exists(file))
|
||||||
|
{
|
||||||
|
if (!can_write(file))
|
||||||
|
return 0;
|
||||||
|
if (!can_read(file))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
flen = strlen(file);
|
flen = strlen(file);
|
||||||
strcpy(key, &(cp[1]));
|
strcpy(key, &(cp[1]));
|
||||||
if ((flen > 3) &&
|
if ((flen > 3) &&
|
||||||
|
@ -206,8 +264,20 @@ save (ImlibImage *im, ImlibProgressFunction progress,
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
db = dbm_open(file, O_RDWR | O_CREAT, 0664);
|
db = dbm_open(file, O_RDWR | O_CREAT, 0664);
|
||||||
|
if (!db)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
usleep((rand() % 0xff) * 1000);
|
||||||
|
db = dbm_open(file, O_RDWR | O_CREAT, 0664);
|
||||||
|
if (db)
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!db)
|
if (!db)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
dkey.dptr = key;
|
dkey.dptr = key;
|
||||||
dkey.dsize = strlen(key);
|
dkey.dsize = strlen(key);
|
||||||
|
|
Loading…
Reference in New Issue