Compare commits

...

4 Commits

Author SHA1 Message Date
Fufu Fang 1a20318654
added more debug statements 2024-05-05 02:55:10 +01:00
Fufu Fang 9a7eabd170
modified debug message 2024-05-05 02:04:31 +01:00
Fufu Fang 01fd2e9559
changed the way debug level works 2024-05-05 02:00:46 +01:00
Fufu Fang be666d72e9
removed semi-colon at the end of a macro 2024-05-05 00:32:00 +01:00
5 changed files with 23 additions and 8 deletions

View File

@ -163,12 +163,15 @@ static int Meta_read(Cache *cf)
return EIO; return EIO;
} }
/*
* TODO: This appears to be broken
*/
if (sizeof(long) != fread(&cf->time, sizeof(long), 1, fp) || if (sizeof(long) != fread(&cf->time, sizeof(long), 1, fp) ||
sizeof(off_t) != fread(&cf->content_length, sizeof(off_t), 1, fp) || sizeof(off_t) != fread(&cf->content_length, sizeof(off_t), 1, fp) ||
sizeof(int) != fread(&cf->blksz, sizeof(int), 1, fp) || sizeof(int) != fread(&cf->blksz, sizeof(int), 1, fp) ||
sizeof(long) != fread(&cf->segbc, sizeof(long), 1, fp) || sizeof(long) != fread(&cf->segbc, sizeof(long), 1, fp) ||
ferror(fp)) { ferror(fp)) {
lprintf(error, "error reading core metadata!\n"); lprintf(error, "error reading core metadata %s!\n", cf->path);
return EIO; return EIO;
} }
@ -541,7 +544,9 @@ static void Cache_free(Cache *cf)
static int Cache_exist(const char *fn) static int Cache_exist(const char *fn)
{ {
char *metafn = path_append(META_DIR, fn); char *metafn = path_append(META_DIR, fn);
lprintf(debug, "metafn: %s\n", metafn);
char *datafn = path_append(DATA_DIR, fn); char *datafn = path_append(DATA_DIR, fn);
lprintf(debug, "datafn: %s\n", datafn);
/* /*
* access() returns 0 on success * access() returns 0 on success
*/ */
@ -551,11 +556,13 @@ static int Cache_exist(const char *fn)
if (no_meta ^ no_data) { if (no_meta ^ no_data) {
lprintf(warning, "Cache file partially missing.\n"); lprintf(warning, "Cache file partially missing.\n");
if (no_meta) { if (no_meta) {
lprintf(debug, "Unlinking datafn: %s\n", datafn);
if (unlink(datafn)) { if (unlink(datafn)) {
lprintf(fatal, "unlink(): %s\n", strerror(errno)); lprintf(fatal, "unlink(): %s\n", strerror(errno));
} }
} }
if (no_data) { if (no_data) {
lprintf(debug, "Unlinking metafn: %s\n", metafn);
if (unlink(metafn)) { if (unlink(metafn)) {
lprintf(fatal, "unlink(): %s\n", strerror(errno)); lprintf(fatal, "unlink(): %s\n", strerror(errno));
} }

View File

@ -100,14 +100,18 @@ static int fs_open(const char *path, struct fuse_file_info *fi)
return -EROFS; return -EROFS;
} }
if (CACHE_SYSTEM_INIT) { if (CACHE_SYSTEM_INIT) {
lprintf(debug, "Cache_open(%s);\n", path);
fi->fh = (uint64_t) Cache_open(path); fi->fh = (uint64_t) Cache_open(path);
if (!fi->fh) { if (!fi->fh) {
/* /*
* The link clearly exists, the cache cannot be opened, attempt * The link clearly exists, the cache cannot be opened, attempt
* cache creation * cache creation
*/ */
lprintf(debug, "Cache_delete(%s);\n", path);
Cache_delete(path); Cache_delete(path);
lprintf(debug, "Cache_create(%s);\n", path);
Cache_create(path); Cache_create(path);
lprintf(debug, "Cache_open(%s);\n", path);
fi->fh = (uint64_t) Cache_open(path); fi->fh = (uint64_t) Cache_open(path);
/* /*
* The cache definitely cannot be opened for some reason. * The cache definitely cannot be opened for some reason.
@ -117,6 +121,7 @@ static int fs_open(const char *path, struct fuse_file_info *fi)
* percentage encoded * percentage encoded
*/ */
if (!fi->fh) { if (!fi->fh) {
lprintf(fatal, "Cache file creation failure for %s.\n", path);
return -ENOENT; return -ENOENT;
} }
} }
@ -145,7 +150,7 @@ fs_readdir(const char *path, void *buf, fuse_fill_dir_t dir_add,
#ifdef DEBUG #ifdef DEBUG
static int j = 0; static int j = 0;
lprintf(debug, "\n!!!!Calling fs_readdir for the %d time!!!!\n", j) lprintf(debug, "!!!!Calling fs_readdir for the %d time!!!!\n", j);
j++; j++;
#endif #endif

View File

@ -646,7 +646,7 @@ LinkTable *LinkTable_new(const char *url)
#ifdef DEBUG #ifdef DEBUG
static int i = 0; static int i = 0;
lprintf(debug, "\n!!!!Calling LinkTable_new for the %d time!!!!\n", i) lprintf(debug, "!!!!Calling LinkTable_new for the %d time!!!!\n", i);
i++; i++;
#endif #endif
@ -806,7 +806,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
* TODO: Save the updated LinkTable * TODO: Save the updated LinkTable
*/ */
lprintf(info, "time_now: %d, index_time: %d\n", time_now, lprintf(info, "time_now: %d, index_time: %d\n", time_now,
next_table->index_time) next_table->index_time);
lprintf(info, "diff: %d, limit: %d\n", time_now - next_table->index_time, lprintf(info, "diff: %d, limit: %d\n", time_now - next_table->index_time,
CONFIG.refresh_timeout); CONFIG.refresh_timeout);
lprintf(info, "Refreshing LinkTable for %s\n", path); lprintf(info, "Refreshing LinkTable for %s\n", path);

View File

@ -15,7 +15,11 @@ int log_level_init()
if (env) { if (env) {
return atoi(env); return atoi(env);
} }
#ifdef DEBUG
return DEFAULT_LOG_LEVEL | debug;
#else
return DEFAULT_LOG_LEVEL; return DEFAULT_LOG_LEVEL;
#endif
} }
void void

View File

@ -1,7 +1,6 @@
#ifndef LOG_H #ifndef LOG_H
#define LOG_H #define LOG_H
#define DEBUG 0
/** /**
* \brief Log types * \brief Log types
*/ */
@ -10,7 +9,7 @@ typedef enum {
error = 1 << 1, error = 1 << 1,
warning = 1 << 2, warning = 1 << 2,
info = 1 << 3, info = 1 << 3,
debug = DEBUG << 4, debug = 1 << 4,
link_lock_debug = 1 << 5, link_lock_debug = 1 << 5,
network_lock_debug = 1 << 6, network_lock_debug = 1 << 6,
cache_lock_debug = 1 << 7, cache_lock_debug = 1 << 7,
@ -21,7 +20,7 @@ typedef enum {
/** /**
* \brief The default log level * \brief The default log level
*/ */
#define DEFAULT_LOG_LEVEL fatal | error | warning | info | debug #define DEFAULT_LOG_LEVEL fatal | error | warning | info
/** /**
* \brief Get the log level from the environment. * \brief Get the log level from the environment.
@ -40,7 +39,7 @@ void log_printf(LogType type, const char *file, const char *func, int line,
* \details This macro automatically prints out the filename and line number * \details This macro automatically prints out the filename and line number
*/ */
#define lprintf(type, ...) \ #define lprintf(type, ...) \
log_printf(type, __FILE__, __func__, __LINE__, __VA_ARGS__); log_printf(type, __FILE__, __func__, __LINE__, __VA_ARGS__)
/** /**
* \brief Print the version information for HTTPDirFS * \brief Print the version information for HTTPDirFS