Skip to content

Commit

Permalink
more tweaks to windows rename handling
Browse files Browse the repository at this point in the history
  • Loading branch information
droundy committed Jun 25, 2016
1 parent 013ba72 commit 9026ae7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
45 changes: 43 additions & 2 deletions bigbro-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,49 @@ int bigbro(const char *workingdir, pid_t *child_ptr,
break;
case RENAME_OP:
i += strlen(q.buf->data+i)+1;
const char *newname = q.buf->data+i;
printf("FIXME: not handling rename %s -> %s\n", name, newname);
const char *from = name;
const char *absto = q.buf->data+i;
printf("handling rename %s -> %s\n", from, absto);

if (lookup_in_hash(&written, from) || lookup_in_hash(&read, from)) {
// Looks like it might be a file!
delete_from_hashset(&written, from);
delete_from_hashset(&read, from);
insert_hashset(&written, absto);
} else {
// I think it might be a directory
char *fromslash = malloc(strlen(from)+2);
strcpy(fromslash, from);
strcat(fromslash, "\\");
char *toslash = malloc(strlen(absto)+2);
strcpy(toslash, absto);
strcat(toslash, "\\");
int fromslashlen = strlen(fromslash);
int toslashlen = strlen(toslash);
for (struct hash_entry *e = written.first; e; e = e->next) {
if (strncmp(e->key, fromslash, fromslashlen) == 0) {
char *newk = malloc(strlen(e->key) - fromslashlen + toslashlen + 1);
strcpy(newk, toslash);
strcat(newk, e->key + fromslashlen);
insert_hashset(&written, newk);
delete_from_hashset(&written, e->key);
}
}
for (struct hash_entry *e = read.first; e; e = e->next) {
if (strncmp(e->key, fromslash, fromslashlen) == 0) {
char *newk = malloc(strlen(e->key) - fromslashlen + toslashlen + 1);
strcpy(newk, toslash);
strcat(newk, e->key + fromslashlen);
insert_hashset(&written, newk);
delete_from_hashset(&read, e->key);
}
}
for (struct hash_entry *e = readdir.first; e; e = e->next) {
if (strncmp(e->key, fromslash, fromslashlen) == 0) {
delete_from_hashset(&readdir, e->key);
}
}
}
break;
case READDIR_OP:
insert_hashset(&readdir, name);
Expand Down
11 changes: 11 additions & 0 deletions tests/rename-directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ def passes(out, err):
th.writes(err, '/tmp/newdir/test'),
])

def passes_windows(out, err):
print('out:\n' + out)
print('err:\n' + err)
return all(
[th.count_writes(err, 2),
th.doesnt_write(err, r'\tmp\subdir2\hello'),
th.doesnt_read(err, r'\tmp\subdir2\test'),
th.writes(err, r'\tmp\newdir\hello'),
th.writes(err, r'\tmp\newdir\test'),
])

needs_symlinks = True
9 changes: 9 additions & 0 deletions tests/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ def passes(out, err):
th.count_readdir(err, 0),
])

def passes_windows(out, err):
print('out:\n' + out)
print('err:\n' + err)
return all(
[th.writes(err, r'\tmp\barbaz'),
th.count_writes(err, 1),
th.count_readdir(err, 0),
])

needs_symlinks = False
2 changes: 2 additions & 0 deletions tests/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def passes(out, err):
])

def passes_windows(out, err):
print('out:\n', out)
print('err:\n', err)
return all(
[th.reads(err, r'\tmp\foo'),
th.count_writes(err, 0),
Expand Down

0 comments on commit 9026ae7

Please sign in to comment.