diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2012-04-25 19:32:13 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2012-04-25 19:32:13 +0200 |
commit | ff33cf46862c7c88ae2250e787dd00f2b946c9e6 (patch) | |
tree | d04b1e0e3f6f599cba08b2d5490e71f6dbe19e59 /pgfuse.c | |
parent | 41594b8a1afc1978f7de64fb34b3adaa1c9009df (diff) | |
download | pgfuse-ff33cf46862c7c88ae2250e787dd00f2b946c9e6.tar.gz pgfuse-ff33cf46862c7c88ae2250e787dd00f2b946c9e6.tar.bz2 |
some work for rename
Diffstat (limited to 'pgfuse.c')
-rw-r--r-- | pgfuse.c | 59 |
1 files changed, 58 insertions, 1 deletions
@@ -1136,6 +1136,63 @@ static int pgfuse_symlink( const char *from, const char *to ) return 0; } +static int pgfuse_rename( const char *from, const char *to ) +{ + PgFuseData *data = (PgFuseData *)fuse_get_context( )->private_data; + PGconn *conn; + int res; + int from_id; + int to_id; + PgMeta from_meta; + PgMeta to_meta; + + if( data->verbose ) { + syslog( LOG_INFO, "Renaming '%s' to '%s' on '%s', thread #%u", + from, to, data->mountpoint, THREAD_ID ); + } + + ACQUIRE( conn ); + PSQL_BEGIN( conn ); + + from_id = psql_read_meta_from_path( conn, from, &from_meta ); + if( from_id < 0 ) { + return from_id; + } + + to_id = psql_read_meta_from_path( conn, to, &to_meta ); + if( to_id < 0 && to_id != -ENOENT ) { + return to_id; + } + + /* destination already exists */ + if( to_id > 0 ) { + /* destination is a file */ + if( S_ISREG( to_meta.mode ) ) { + if( strcmp( from, to ) == 0 ) { + /* source equal to destination? This should succeed */ + return 0; + } else { + /* otherwise bail out */ + return -EEXIST; + } + } + /* TODO: handle all other cases */ + return -EINVAL; + } + + /* TODO: enable also those cases later */ + if( S_ISDIR( from_meta.mode ) || + S_ISLNK( from_meta.mode ) ) { + return -EINVAL; + } + + res = psql_rename( conn, from, to ); + + PSQL_COMMIT( conn ); RELEASE( conn ); + + return res; +} + static int pgfuse_readlink( const char *path, char *buf, size_t size ) { PgFuseData *data = (PgFuseData *)fuse_get_context( )->private_data; @@ -1226,7 +1283,7 @@ static struct fuse_operations pgfuse_oper = { .unlink = pgfuse_unlink, .rmdir = pgfuse_rmdir, .symlink = pgfuse_symlink, - .rename = NULL, + .rename = pgfuse_rename, .link = NULL, .chmod = pgfuse_chmod, .chown = pgfuse_chown, |