From: Michael Vrable Date: Fri, 30 Oct 2009 22:48:14 +0000 (-0700) Subject: Start work on a rename operation. Not yet complete. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=45f3ec339de4b7efa9ef5978b79148c25e0c49b2;p=bluesky.git Start work on a rename operation. Not yet complete. --- diff --git a/bluesky/dir.c b/bluesky/dir.c index cb3b23f..724320a 100644 --- a/bluesky/dir.c +++ b/bluesky/dir.c @@ -121,8 +121,8 @@ gboolean bluesky_directory_insert(BlueSkyInode *dir, return TRUE; } -/* Remove an from a directory. Should be called with the inode lock already - * held. */ +/* Remove an entry from a directory. Should be called with the inode lock + * already held. */ gboolean bluesky_directory_remove(BlueSkyInode *dir, gchar *name) { g_return_val_if_fail(dir->type == BLUESKY_DIRECTORY, FALSE); @@ -150,6 +150,40 @@ gboolean bluesky_directory_remove(BlueSkyInode *dir, gchar *name) return TRUE; } +/* Rename a file. If desired (if overwrite is true) and if the target already + * exists, it will be unlinked first. */ +gboolean bluesky_rename(BlueSkyInode *dir1, gchar *name1, + BlueSkyInode *dir2, gchar *name2, + gboolean case_sensitive, + gboolean overwrite) +{ + g_return_val_if_fail(dir1->type == BLUESKY_DIRECTORY, FALSE); + g_return_val_if_fail(dir2->type == BLUESKY_DIRECTORY, FALSE); + + BlueSkyDirent *d1, *d2; + + d1 = g_hash_table_lookup(case_sensitive ? dir1->dirhash + : dir1->dirhash_folded, name1); + d2 = g_hash_table_lookup(case_sensitive ? dir2->dirhash + : dir2->dirhash_folded, name2); + + if (d1 == NULL) + return FALSE; + + /* Check that this rename does not cause a directory to be moved into one + * of its descendants, as that would create a loop of directories + * disconnected from the root. */ + /* TODO */ + + if (d2 != NULL) { + if (!overwrite) + return FALSE; + + bluesky_directory_remove(dir2, name2); + } + +} + /* Dump the contents of a directory to stdout. Debugging only. */ void bluesky_directory_dump(BlueSkyInode *dir) {