Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove support for non-writable disk cache entries.

This removes the support for opening disk cache entries O_RDONLY,
which as far as I am aware nobody has ever used.
  • Loading branch information...
commit 2fe49ea7851b388679a9cc0e5cf8ff3b3118cc1f 1 parent 580ac1e
@jech jech authored
Showing with 19 additions and 40 deletions.
  1. +18 −38 diskcache.c
  2. +1 −2  diskcache.h
View
56 diskcache.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2003-2006 by Juliusz Chroboczek
+Copyright (c) 2003-2010 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -49,7 +49,7 @@ int preciseExpiry = 0;
static DiskCacheEntryRec negativeEntry = {
NULL, NULL,
- -1, -1, -1, -1, 0, 0, 0, NULL, NULL
+ -1, -1, -1, -1, 0, 0, NULL, NULL
};
#ifndef LOCAL_ROOT
@@ -1132,12 +1132,12 @@ objectHasDiskEntry(ObjectPtr object)
}
static DiskCacheEntryPtr
-makeDiskEntry(ObjectPtr object, int writeable, int create)
+makeDiskEntry(ObjectPtr object, int create)
{
DiskCacheEntryPtr entry = NULL;
char buf[1024];
int fd = -1;
- int negative = 0, isWriteable = 0, size = -1, name_len = -1;
+ int negative = 0, size = -1, name_len = -1;
char *name = NULL;
off_t offset = -1;
int body_offset = -1;
@@ -1145,8 +1145,8 @@ makeDiskEntry(ObjectPtr object, int writeable, int create)
int local = (object->flags & OBJECT_LOCAL) != 0;
int dirty = 0;
- if(local && (writeable || create))
- return NULL;
+ if(local && create)
+ return NULL;
if(!local && !(object->flags & OBJECT_PUBLIC))
return NULL;
@@ -1164,7 +1164,7 @@ makeDiskEntry(ObjectPtr object, int writeable, int create)
if(object->disk_entry) {
entry = object->disk_entry;
CHECK_ENTRY(entry);
- if(entry != &negativeEntry && (!writeable || entry->writeable)) {
+ if(entry != &negativeEntry) {
/* We'll keep the entry -- put it at the front. */
if(entry != diskEntries && entry != &negativeEntry) {
entry->previous->next = entry->next;
@@ -1197,14 +1197,8 @@ makeDiskEntry(ObjectPtr object, int writeable, int create)
return NULL;
name_len = urlFilename(buf, 1024, object->key, object->key_size);
if(name_len < 0) return NULL;
- if(!negative) {
- isWriteable = 1;
+ if(!negative)
fd = open(buf, O_RDWR | O_BINARY);
- if(fd < 0 && !writeable && errno == EACCES) {
- isWriteable = 0;
- fd = open(buf, O_RDONLY | O_BINARY);
- }
- }
if(fd >= 0) {
rc = validateEntry(object, fd, &body_offset, &offset);
if(rc >= 0) {
@@ -1224,7 +1218,6 @@ makeDiskEntry(ObjectPtr object, int writeable, int create)
if(fd < 0 && create && name_len > 0 &&
!(object->flags & OBJECT_INITIAL)) {
- isWriteable = 1;
fd = createFile(buf, diskCacheRoot->length);
if(fd < 0)
return NULL;
@@ -1262,7 +1255,6 @@ makeDiskEntry(ObjectPtr object, int writeable, int create)
localFilename(buf, 1024, object->key, object->key_size);
if(name_len < 0)
return NULL;
- isWriteable = 0;
fd = open(buf, O_RDONLY | O_BINARY);
if(fd >= 0) {
if(validateEntry(object, fd, &body_offset, NULL) < 0) {
@@ -1303,7 +1295,6 @@ makeDiskEntry(ObjectPtr object, int writeable, int create)
entry->offset = offset;
entry->size = size;
entry->metadataDirty = dirty;
- entry->writeable = isWriteable;
entry->next = diskEntries;
if(diskEntries)
@@ -1342,7 +1333,7 @@ rewriteEntry(ObjectPtr object)
close(fd);
return -1;
}
- entry = makeDiskEntry(object, 1, 1);
+ entry = makeDiskEntry(object, 1);
if(!entry) {
close(fd);
return -1;
@@ -1415,7 +1406,7 @@ destroyDiskEntry(ObjectPtr object, int d)
assert(!entry || !entry->local || !d);
if(d && !entry)
- entry = makeDiskEntry(object, 1, 0);
+ entry = makeDiskEntry(object, 0);
CHECK_ENTRY(entry);
@@ -1441,12 +1432,12 @@ destroyDiskEntry(ObjectPtr object, int d)
} else {
if(entry && entry->metadataDirty)
writeoutMetadata(object);
- makeDiskEntry(object, 1, 0);
+ makeDiskEntry(object, 0);
/* rewriteDiskEntry may change the disk entry */
entry = object->disk_entry;
if(entry == NULL || entry == &negativeEntry)
return 0;
- if(entry->writeable && diskCacheWriteoutOnClose > 0)
+ if(diskCacheWriteoutOnClose > 0)
reallyWriteoutToDisk(object, -1, diskCacheWriteoutOnClose);
}
again:
@@ -1483,7 +1474,7 @@ destroyDiskEntry(ObjectPtr object, int d)
ObjectPtr
objectGetFromDisk(ObjectPtr object)
{
- DiskCacheEntryPtr entry = makeDiskEntry(object, 0, 0);
+ DiskCacheEntryPtr entry = makeDiskEntry(object, 0);
if(!entry) return NULL;
return object;
}
@@ -1535,7 +1526,7 @@ objectFillFromDisk(ObjectPtr object, int offset, int chunks)
/* This has the side-effect of revalidating the entry, which is
what makes HEAD requests work. */
- entry = makeDiskEntry(object, 0, 0);
+ entry = makeDiskEntry(object, 0);
if(!entry)
return 0;
@@ -1666,7 +1657,7 @@ reallyWriteoutToDisk(ObjectPtr object, int upto, int max)
if((object->flags & OBJECT_DISK_ENTRY_COMPLETE) && !object->disk_entry)
return 0;
- entry = makeDiskEntry(object, 1, 1);
+ entry = makeDiskEntry(object, 1);
if(!entry) return 0;
assert(!entry->local);
@@ -1686,25 +1677,14 @@ reallyWriteoutToDisk(ObjectPtr object, int upto, int max)
if(entry->size >= upto)
goto done;
- if(!entry->writeable) {
- entry = makeDiskEntry(object, 1, 1);
- if(!entry)
- return 0;
- if(!entry->writeable)
- return 0;
- diskEntrySize(object);
- if(entry->size < 0)
- return 0;
- }
-
offset = entry->size;
/* Avoid a seek in case we start writing at the beginning */
if(offset == 0 && entry->metadataDirty) {
writeoutMetadata(object);
/* rewriteDiskEntry may change the entry */
- entry = makeDiskEntry(object, 1, 0);
- if(entry == NULL || !entry->writeable)
+ entry = makeDiskEntry(object, 0);
+ if(entry == NULL)
return 0;
}
@@ -1756,7 +1736,7 @@ writeoutMetadata(ObjectPtr object)
(object->flags & OBJECT_LOCAL))
return 0;
- entry = makeDiskEntry(object, 1, 0);
+ entry = makeDiskEntry(object, 0);
if(entry == NULL || entry == &negativeEntry)
goto fail;
View
3  diskcache.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2003-2006 by Juliusz Chroboczek
+Copyright (c) 2003-2010 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,6 @@ typedef struct _DiskCacheEntry {
off_t size;
int body_offset;
short local;
- short writeable;
short metadataDirty;
struct _DiskCacheEntry *next;
struct _DiskCacheEntry *previous;
Please sign in to comment.
Something went wrong with that request. Please try again.