Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/14286b381b12034140768800c7ba10baa7c3b334
...commit
http://git.netsurf-browser.org/netsurf.git/commit/14286b381b12034140768800c7ba10baa7c3b334
...tree
http://git.netsurf-browser.org/netsurf.git/tree/14286b381b12034140768800c7ba10baa7c3b334
The branch, master has been updated
via 14286b381b12034140768800c7ba10baa7c3b334 (commit)
via 5dd1a81f9c97d852faa54e0d96482b69739fe8dc (commit)
from 921568166bc924f2c5e587095012d7a34a472ed5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=14286b381b12034140768800c7ba10baa7c3b334
commit 14286b381b12034140768800c7ba10baa7c3b334
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>
fs_backing_store: Remove cache on failure to init
If we fail to init the control file for reasons other than it
not being found, we blow away the cache in its entirety and then
try again. We warn if the removal fails, but carry on regardless
since right now the worst that'll happen is that we'll end up
with more on disk than we know about in the cache.
Signed-off-by: Daniel Silverstone <[email protected]>
diff --git a/content/fs_backing_store.c b/content/fs_backing_store.c
index ff1c265..458866c 100644
--- a/content/fs_backing_store.c
+++ b/content/fs_backing_store.c
@@ -62,7 +62,7 @@
#define DEFAULT_ENTRY_SIZE 16
/** Backing store file format version */
-#define CONTROL_VERSION 201
+#define CONTROL_VERSION 202
/** Number of milliseconds after a update before control data maintenance is
performed */
#define CONTROL_MAINT_TIME 10000
@@ -1461,8 +1461,22 @@ initialise(const struct llcache_store_parameters
*parameters)
/* read store control and create new if required */
ret = read_control(newstate);
if (ret != NSERROR_OK) {
- NSLOG(netsurf, ERROR, "read control failed %s",
- messages_get_errorcode(ret));
+ if (ret == NSERROR_NOT_FOUND) {
+ NSLOG(netsurf, INFO, "cache control file not found,
making fresh");
+ } else {
+ NSLOG(netsurf, ERROR, "read control failed %s",
+ messages_get_errorcode(ret));
+ ret = netsurf_recursive_rm(newstate->path);
+ if (ret != NSERROR_OK) {
+ NSLOG(netsurf, WARNING, "Error `%s` while
removing `%s`",
+ messages_get_errorcode(ret),
newstate->path);
+ NSLOG(netsurf, WARNING, "Unable to clean up
partial cache state.");
+ NSLOG(netsurf, WARNING, "Funky behaviour may
ensue.");
+ } else {
+ NSLOG(netsurf, INFO, "Successfully removed old
cache from `%s`",
+ newstate->path);
+ }
+ }
ret = write_control(newstate);
if (ret == NSERROR_OK) {
unlink_entries(newstate);
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=5dd1a81f9c97d852faa54e0d96482b69739fe8dc
commit 5dd1a81f9c97d852faa54e0d96482b69739fe8dc
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>
utils/file: Add netsurf_recursive_rm
This is to be used to remove the disc cache (and other things
if useful in the future)
Signed-off-by: Daniel Silverstone <[email protected]>
diff --git a/utils/file.c b/utils/file.c
index cc82657..7eff6a7 100644
--- a/utils/file.c
+++ b/utils/file.c
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <errno.h>
#include "desktop/gui_internal.h"
@@ -35,6 +36,7 @@
#include "utils/nsurl.h"
#include "utils/string.h"
#include "utils/file.h"
+#include "utils/dirent.h"
/**
* Generate a posix path from one or more component elemnts.
@@ -307,3 +309,76 @@ nserror netsurf_mkdir_all(const char *fname)
{
return guit->file->mkdir_all(fname);
}
+
+/* exported interface documented in utils/file.h */
+nserror
+netsurf_recursive_rm(const char *path)
+{
+ struct dirent **listing = NULL; /* directory entry listing */
+ int nentries, ent;
+ nserror ret = NSERROR_OK;
+ struct stat ent_stat; /* stat result of leaf entry */
+ char *leafpath = NULL;
+ const char *leafname;
+
+ nentries = scandir(path, &listing, 0, alphasort);
+
+ if (nentries < 0) {
+ switch (errno) {
+ case ENOENT:
+ return NSERROR_NOT_FOUND;
+ default:
+ return NSERROR_UNKNOWN;
+ }
+ }
+
+ for (ent = 0; ent < nentries; ent++) {
+ leafname = listing[ent]->d_name;
+ if (strcmp(leafname, ".") == 0 ||
+ strcmp(leafname, "..") == 0)
+ continue;
+ ret = netsurf_mkpath(&leafpath, NULL, 2, path, leafname);
+ if (ret != NSERROR_OK) goto out;
+ if (stat(leafpath, &ent_stat) != 0) {
+ goto out_via_errno;
+ }
+ if (S_ISDIR(ent_stat.st_mode)) {
+ ret = netsurf_recursive_rm(leafpath);
+ if (ret != NSERROR_OK) goto out;
+ } else {
+ if (unlink(leafpath) != 0) {
+ goto out_via_errno;
+ }
+ }
+ free(leafpath);
+ leafpath = NULL;
+ }
+
+ if (rmdir(path) != 0) {
+ goto out_via_errno;
+ }
+
+ goto out;
+
+out_via_errno:
+ switch (errno) {
+ case ENOENT:
+ ret = NSERROR_NOT_FOUND;
+ break;
+ default:
+ ret = NSERROR_UNKNOWN;
+ }
+out:
+ if (listing != NULL) {
+ for (ent = 0; ent < nentries; ent++) {
+ free(listing[ent]);
+ }
+ free(listing);
+ }
+
+ if (leafpath != NULL) {
+ free(leafpath);
+ }
+
+ return ret;
+}
diff --git a/utils/file.h b/utils/file.h
index 0282c35..809ffe4 100644
--- a/utils/file.h
+++ b/utils/file.h
@@ -172,4 +172,15 @@ nserror netsurf_path_to_nsurl(const char *path, struct
nsurl **url);
*/
nserror netsurf_mkdir_all(const char *fname);
+/**
+ * Recursively remove a directory
+ *
+ * If this returns a failure code, there's an unpredictable amount left
+ * unremoved.
+ *
+ * @param path The path to recursively remove
+ * @return NSERROR_OK on success, or an error code on failure.
+ */
+nserror netsurf_recursive_rm(const char *path);
+
#endif
-----------------------------------------------------------------------
Summary of changes:
content/fs_backing_store.c | 20 ++++++++++--
utils/file.c | 75 ++++++++++++++++++++++++++++++++++++++++++++
utils/file.h | 11 +++++++
3 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/content/fs_backing_store.c b/content/fs_backing_store.c
index ff1c265..458866c 100644
--- a/content/fs_backing_store.c
+++ b/content/fs_backing_store.c
@@ -62,7 +62,7 @@
#define DEFAULT_ENTRY_SIZE 16
/** Backing store file format version */
-#define CONTROL_VERSION 201
+#define CONTROL_VERSION 202
/** Number of milliseconds after a update before control data maintenance is
performed */
#define CONTROL_MAINT_TIME 10000
@@ -1461,8 +1461,22 @@ initialise(const struct llcache_store_parameters
*parameters)
/* read store control and create new if required */
ret = read_control(newstate);
if (ret != NSERROR_OK) {
- NSLOG(netsurf, ERROR, "read control failed %s",
- messages_get_errorcode(ret));
+ if (ret == NSERROR_NOT_FOUND) {
+ NSLOG(netsurf, INFO, "cache control file not found,
making fresh");
+ } else {
+ NSLOG(netsurf, ERROR, "read control failed %s",
+ messages_get_errorcode(ret));
+ ret = netsurf_recursive_rm(newstate->path);
+ if (ret != NSERROR_OK) {
+ NSLOG(netsurf, WARNING, "Error `%s` while
removing `%s`",
+ messages_get_errorcode(ret),
newstate->path);
+ NSLOG(netsurf, WARNING, "Unable to clean up
partial cache state.");
+ NSLOG(netsurf, WARNING, "Funky behaviour may
ensue.");
+ } else {
+ NSLOG(netsurf, INFO, "Successfully removed old
cache from `%s`",
+ newstate->path);
+ }
+ }
ret = write_control(newstate);
if (ret == NSERROR_OK) {
unlink_entries(newstate);
diff --git a/utils/file.c b/utils/file.c
index cc82657..7eff6a7 100644
--- a/utils/file.c
+++ b/utils/file.c
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <errno.h>
#include "desktop/gui_internal.h"
@@ -35,6 +36,7 @@
#include "utils/nsurl.h"
#include "utils/string.h"
#include "utils/file.h"
+#include "utils/dirent.h"
/**
* Generate a posix path from one or more component elemnts.
@@ -307,3 +309,76 @@ nserror netsurf_mkdir_all(const char *fname)
{
return guit->file->mkdir_all(fname);
}
+
+/* exported interface documented in utils/file.h */
+nserror
+netsurf_recursive_rm(const char *path)
+{
+ struct dirent **listing = NULL; /* directory entry listing */
+ int nentries, ent;
+ nserror ret = NSERROR_OK;
+ struct stat ent_stat; /* stat result of leaf entry */
+ char *leafpath = NULL;
+ const char *leafname;
+
+ nentries = scandir(path, &listing, 0, alphasort);
+
+ if (nentries < 0) {
+ switch (errno) {
+ case ENOENT:
+ return NSERROR_NOT_FOUND;
+ default:
+ return NSERROR_UNKNOWN;
+ }
+ }
+
+ for (ent = 0; ent < nentries; ent++) {
+ leafname = listing[ent]->d_name;
+ if (strcmp(leafname, ".") == 0 ||
+ strcmp(leafname, "..") == 0)
+ continue;
+ ret = netsurf_mkpath(&leafpath, NULL, 2, path, leafname);
+ if (ret != NSERROR_OK) goto out;
+ if (stat(leafpath, &ent_stat) != 0) {
+ goto out_via_errno;
+ }
+ if (S_ISDIR(ent_stat.st_mode)) {
+ ret = netsurf_recursive_rm(leafpath);
+ if (ret != NSERROR_OK) goto out;
+ } else {
+ if (unlink(leafpath) != 0) {
+ goto out_via_errno;
+ }
+ }
+ free(leafpath);
+ leafpath = NULL;
+ }
+
+ if (rmdir(path) != 0) {
+ goto out_via_errno;
+ }
+
+ goto out;
+
+out_via_errno:
+ switch (errno) {
+ case ENOENT:
+ ret = NSERROR_NOT_FOUND;
+ break;
+ default:
+ ret = NSERROR_UNKNOWN;
+ }
+out:
+ if (listing != NULL) {
+ for (ent = 0; ent < nentries; ent++) {
+ free(listing[ent]);
+ }
+ free(listing);
+ }
+
+ if (leafpath != NULL) {
+ free(leafpath);
+ }
+
+ return ret;
+}
diff --git a/utils/file.h b/utils/file.h
index 0282c35..809ffe4 100644
--- a/utils/file.h
+++ b/utils/file.h
@@ -172,4 +172,15 @@ nserror netsurf_path_to_nsurl(const char *path, struct
nsurl **url);
*/
nserror netsurf_mkdir_all(const char *fname);
+/**
+ * Recursively remove a directory
+ *
+ * If this returns a failure code, there's an unpredictable amount left
+ * unremoved.
+ *
+ * @param path The path to recursively remove
+ * @return NSERROR_OK on success, or an error code on failure.
+ */
+nserror netsurf_recursive_rm(const char *path);
+
#endif
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org