Skip to content

Commit

Permalink
Reverted to file getattr through file_cabinet_lookup_file
Browse files Browse the repository at this point in the history
- Added a compile flag to disable all logging
- Removed unnecessary logic in get_tags_list
- Corrected return code for file getattr
- Corrected database drop logic in tagfs initialization
- Made the generate_testdb.pl script actually functional again
- Added a progress indicator (a '.' prints for each test completed) to
  acceptance_test.pl
  • Loading branch information
mwatts15 committed Jan 19, 2015
1 parent 35cbff8 commit 78804bd
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 85 deletions.
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -12,8 +12,10 @@ MARCO = ./marco.pl
# define the executable file
MAIN = tagfs

OPT?=-Og

# define any compile-time flags
CFLAGS = -O1 -std=c99 -Wall -g -gdwarf-2 -g3 `pkg-config --cflags glib-2.0 fuse` -D_POSIX_C_SOURCE=201809 -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -DTAGFS_BUILD
CFLAGS += $(OPT) -std=c99 -Wall -g -gdwarf-2 -g3 `pkg-config --cflags glib-2.0 fuse` -D_POSIX_C_SOURCE=201809 -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -DTAGFS_BUILD

# define any directories containing header files other than /usr/include
#
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -33,7 +33,7 @@ To mount TagFS

./tagfs <mount directory>

Where `<mount directory>` is an empty directory. TagFS will create the files it needs in what it thinks is your user-data directory (at `~/.local/share/tagfs` on Linux). You can add files by moving them to the mount directory. Please unmount TagFS properly or you may lose data from changes made while mounted.
Where `<mount directory>` is an empty directory. TagFS will create the files it needs in what it thinks is your user-data directory (at `~/.local/share/tagfs` on Linux). You can add files by moving them to the mount directory. Unmount TagFS properly or you may lose data from changes made while mounted.

As TagFS is still in active development, the database format has changed and may change in the future. There is code to migrate data from an earlier format to the current one. If, in the future, a change to the database would require a loss of data, the database will not be upgraded automatically. In any case, if an upgrade is attempted on your database, it will be backed up first.

Expand Down Expand Up @@ -79,6 +79,10 @@ A SQLite database of files and their associated tags is loaded on mount and mana

As stated, the real files are stored in a separate directory outside of the mount point. The names of these files are the id numbers of the associated tagfs file.

MISCELLANEOUS
=============
If you have a volume monitor running (i.e., gvfs-udisks2-volume-monitor), you may see a CPU spike on mount.

QUESTIONS
=========
If you have any questions for me or about TagFS, don't hesitate to contact me -- I'd be happy to help.
4 changes: 2 additions & 2 deletions file_cabinet.c
Expand Up @@ -198,7 +198,7 @@ int file_cabinet_drawer_size (FileCabinet *fc, file_id_t key)
sqlite3_bind_int(stmt, 1, key);
int sum = 0;
int status;
while ((status = sql_step(stmt)) == SQLITE_ROW)
while ((status = sqlite3_step(stmt)) == SQLITE_ROW)
{
sum++;
}
Expand Down Expand Up @@ -237,7 +237,7 @@ GList *_sqlite_getfile_stmt(FileCabinet *fc, file_id_t key)

GList *res = NULL;

while ((status = sql_step(stmt)) == SQLITE_ROW)
while ((status = sqlite3_step(stmt)) == SQLITE_ROW)
{
int id = sqlite3_column_int(stmt, 0);
/* get the actual file */
Expand Down
4 changes: 4 additions & 0 deletions log.c
Expand Up @@ -76,16 +76,20 @@ void vlog_msg0 (int log_level, const char *format, va_list ap)

void log_msg1 (int log_level, const char *file, int line_number, const char *format, ...)
{
#ifndef NO_LOGGING
/* Does some extra things like print the log level
* and line number
*/
if (!SHOULD_LOG(log_level))
return;
va_list ap;
va_start(ap, format);
lock_log();
log_msg0(log_level, "%s:%s:%d:", _level_names[log_level], file, line_number);
vlog_msg0(log_level, format, ap);
log_msg0(log_level, "\n");
unlock_log();
#endif
}

void _lock_log (int operation)
Expand Down
8 changes: 8 additions & 0 deletions log.h
Expand Up @@ -22,9 +22,17 @@ typedef enum {
* should be used sparingly. debug,info,warn, or error
* should be prefered
*/
#ifdef NO_LOGGING
#define log_msg(...)
#else
#define log_msg(...) log_msg0(g_log_filtering_level, __VA_ARGS__)
#endif

#ifdef NO_LOGGING
#define delio(LEVEL,...)
#else
#define delio(LEVEL,...) log_msg1((LEVEL), __FILE__, __LINE__, __VA_ARGS__)
#endif

#define debug(...) delio(DEBUG, __VA_ARGS__)
#define info(...) delio(INFO, __VA_ARGS__)
Expand Down
2 changes: 1 addition & 1 deletion sql.c
Expand Up @@ -125,7 +125,7 @@ void sql_commit(sqlite3 *db)
*/
int try_upgrade_db (sqlite3 *db)
{
try_upgrade_db0(db, DB_VERSION);
return try_upgrade_db0(db, DB_VERSION);
}

int try_upgrade_db0 (sqlite3 *db, int target_version)
Expand Down
1 change: 1 addition & 0 deletions sql.h
Expand Up @@ -20,6 +20,7 @@ sqlite3* sql_init (const char *db_fname);
gboolean database_init(sqlite3 *db);
int database_backup (sqlite3 *db);
gboolean database_clear_backups (sqlite3 *db);
int try_upgrade_db0 (sqlite3 *db, int target_version);

#define DB_VERSION 2
#define DB_VERSION_S "2"
Expand Down
21 changes: 7 additions & 14 deletions tagdb.c
Expand Up @@ -148,11 +148,16 @@ gulong tagdb_ntags (TagDB *db)
return tag_bucket_size(db);
}

GList *tagdb_tag_names (TagDB *db)
GList *tagdb_tag_ids (TagDB *db)
{
return g_hash_table_get_keys(db->tags);
}

GList *tagdb_tags (TagDB *db)
{
return g_hash_table_get_values(db->tags);
}

/* This guy needs to take a tag path, create each of the tags in the path,
* establish their subtag relationships, insert the tags into the TagDB,
* and return the end tag. It does this by getting TagPathInfo from the
Expand Down Expand Up @@ -356,19 +361,7 @@ GList *tag_files(TagDB *db, Tag *t)

File *lookup_file (TagDB *db, tagdb_key_t keys, char *name)
{
/* XXX: This is likely to be quite slow when looking up many files */
GList *l = get_files_list(db, keys);
File *res = NULL;
LL(l, it)
{
if (file_name_str_cmp((AbstractFile*)it->data, name) == 0)
{
res = it->data;
break;
}
}LL_END;
g_list_free(l);
return res;
return file_cabinet_lookup_file(db->files, keys, name);
}

Tag *retrieve_tag (TagDB *db, file_id_t id)
Expand Down
3 changes: 2 additions & 1 deletion tagdb.h
Expand Up @@ -134,7 +134,8 @@ void put_file_in_untagged(TagDB *db, File *f);
void tagdb_tag_set_subtag(TagDB *db, Tag *sup, Tag *sub);

gulong tagdb_ntags (TagDB *db);
GList *tagdb_tag_names (TagDB *db);
GList *tagdb_tag_ids (TagDB *db);
GList *tagdb_tags (TagDB *db);

GList *tagdb_untagged_items (TagDB *db);
GList *tagdb_all_files (TagDB *db);
Expand Down
10 changes: 9 additions & 1 deletion tagdb_fs.lc
Expand Up @@ -191,7 +191,15 @@ File *is_file (const char *path)
{
char *fpath = get_file_copies_path(path);
debug("getattr:fpath = %s", fpath);
retstat = lstat(fpath, statbuf);
int stat = lstat(fpath, statbuf);
if (stat == -1)
{
retstat = -errno;
}
else
{
retstat = 0;
}
debug("getattr:retstat = %d", retstat);
g_free(fpath);
}
Expand Down
52 changes: 8 additions & 44 deletions tagdb_util.lc
@@ -1,3 +1,4 @@
#include <assert.h>
#include "log.h"
#include "tag.h"
#include "tagdb.h"
Expand All @@ -6,61 +7,24 @@
#include "tagdb_util.h"
#include "util.h"

struct agg_children_data
{
TagDB *db;
GList *res;
};

void agg_tag_files (Tag *t, gpointer data)
{
struct agg_children_data *d = data;
GList *l = file_cabinet_get_drawer_l(d->db->files, tag_id(t));
d->res = g_list_concat(d->res, l);
}

void agg_tag_tags (Tag *t, gpointer data)
{
struct agg_children_data *d = data;
d->res = g_list_prepend(d->res, TO_SP(tag_id(t)));
}

GList *_tag_intersection(TagDB *db, tagdb_key_t key);
GList *get_tags_list (TagDB *db, tagdb_key_t key)
{
%(log);

GList *tags = NULL;
if (key_is_empty(key))
{
tags = tagdb_tag_names(db);
}
else
{
tags = _tag_intersection(db, key);
return tagdb_tags(db);
}

GList *tags = _tag_intersection(db, key);
GList *res = NULL;
LL(tags, list)
{
int skip = 0;
/* For skipping over entries that have already appeared
* in the path
*/
KL(key, i)
{
if (TO_S(list->data) == key_ref(key,i))
{
skip = 1;
}
} KL_END;

if (!skip)
{
Tag *t = retrieve_tag(db, TO_S(list->data));
if (t != NULL)
res = g_list_prepend(res, t);
}
LL(tags, it)
{
Tag *t = retrieve_tag(db, TO_S(it->data));
assert(t != NULL);
res = g_list_prepend(res, t);
} LL_END;
g_list_free(tags);
return res;
Expand Down
13 changes: 2 additions & 11 deletions tagfs.lc
Expand Up @@ -200,20 +200,11 @@ int main (int argc, char **argv)
debug("argv[%d] = '%s'", i, argv[i]);
}

int db_fd = open(db_fname, O_RDONLY);
if (db_fd == -1)
if (do_drop_db)
{
if (do_drop_db)
{
unlink(db_fname);
}
}
else
{
close(db_fd);
unlink(db_fname);
}


sqlite3* sqldb = sql_init(db_fname);
if (!sqldb)
{
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance_test.pl
Expand Up @@ -832,6 +832,7 @@ sub run_test
&setupTestDir;
subtest $test_name => \&$test;
&cleanupTestDir;
print ".";
}

sub run_named_tests
Expand Down
21 changes: 12 additions & 9 deletions tests/generate_testdb.pl
Expand Up @@ -10,9 +10,9 @@
my $mountDirName;
my $dataDirName;
my $DATABASE = "test.db";
my $MAX_FILES = 1000;
my $MAX_TAGS = 500;
my $MAX_TAGS_PER_FILE = 30;
my $MAX_FILES = 10;
my $MAX_TAGS = 5;
my $MAX_TAGS_PER_FILE = 3;

($MAX_TAGS_PER_FILE < $MAX_TAGS) || die "You can't have more tags per file than you have tags.";

Expand All @@ -33,8 +33,9 @@ sub setup
{
$mountDirName = make_tempdir("mount");
$dataDirName = make_tempdir("data");
my $cmd = "../tagfs --data-dir=$dataDirName -b $DATABASE $mountDirName";
system($cmd) or die "Couldn't exec tagfs: $!\n";
my $cmd = "../tagfs --drop-db -g 0 --log-file generate.log --data-dir=$dataDirName -b $DATABASE $mountDirName";
print("$cmd\n");
(system($cmd) == 0) or die "Couldn't exec tagfs: $!\n";
}

sub new_file
Expand Down Expand Up @@ -79,7 +80,8 @@ sub make_files
{
for (my $file_idx = 0; $file_idx < $MAX_FILES; $file_idx++)
{
my $file = $mountDirName . "/" . $file_idx;
my $file_name = $file_idx + 1;
my $file = "$mountDirName/$file_name";
if (not new_file($file))
{
print STDERR "Couldn't create $file. Exiting.";
Expand All @@ -93,7 +95,7 @@ sub make_tags
{
for (my $tag_idx = 0; $tag_idx < $MAX_TAGS; $tag_idx++)
{
my $dir = $mountDirName . "/" . $tag_idx;
my $dir = "$mountDirName/d$tag_idx";
if (not (mkdir($dir)))
{
print STDERR "Couldn't create $dir. Exiting.";
Expand All @@ -119,11 +121,12 @@ sub add_tags_to_files
# XXX: This assumes that the name of the file is the same as its file_id
# because of the way we created the files. This isn't a correct assumption
# generally.
rename "$mountDirName/$file_idx#", "$mountDirName/$tag_to_add/$file_idx";
rename "$mountDirName/$file_idx#", "$mountDirName/d$tag_to_add/$file_idx";
}
}
}

setup();
generate();
END {
teardown();
}

0 comments on commit 78804bd

Please sign in to comment.