-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.c
45 lines (40 loc) · 1.34 KB
/
rename.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "dogfs.h"
static int
dogfs_rename_trx(connection_t *c, const char *from, const char *to)
{
char *from_file, *to_file;
inode_t from_dir = resolve_dir_inode(c, from, &from_file);
if (from_file == INVALID_INODE)
return -ENOENT;
inode_t to_dir = resolve_dir_inode(c, to, &to_file);
if (to_file == INVALID_INODE)
return -ENOENT;
inode_t existing = resolve_inode_from(c, to_file, to_dir);
if (existing != INVALID_INODE) {
int r = inode_rmdir_trx(c, to_dir, existing, to_file);
if (r) return r;
}
inode_t inode = resolve_inode_from(c, from_file, from_dir);
if (inode == INVALID_INODE)
return -ENOENT;
cache_remove(inode);
MYSQL_BIND params[4];
bind_inode(params + 0, &to_dir);
bind_string(params + 1, to_file);
bind_inode(params + 2, &from_dir);
bind_string(params + 3, from_file);
return run_with_statement(c,
"update paths set directory=?, filename=?"
" where directory=? and filename=?", params,
check_update);
}
static int
dogfs_rename_c(connection_t *c, const char *from, const char *to)
{
return run_with_trx(dogfs_rename_trx, c, from, to);
}
int
dogfs_rename(const char *from, const char *to)
{
return run_with_connection(dogfs_rename_c, from, to);
}