facebook / facebook/hhvm

rename() of directory creates destination as empty file and incorrectly reports success

Open
#8,175 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

### HHVM Version
3.26.0-dev

### Operating System and Version
CentOS 7

### Standalone code, or other way to reproduce the problem
```
# src_dir and dest_dir should be on different file systems
# to reproduce the problem.
$src_dir = "/dev/shm/php-test";
$dest_dir = "/tmp/php-test";

mkdir($src_dir);
$a = fopen("$src_dir/a.txt", "w");
fwrite($a, "a\n");
fclose($a);
$b = fopen("$src_dir/b.txt", "w");
fwrite($b, "b\n");
fclose($b);

if (rename($src_dir, $dest_dir)) {
echo("rename succeeded\n");
} else {
echo("rename failed\n");
}
```

### Expected result
/tmp/php-test exists and contains two files, a.txt and b.txt
(Or alternatively the rename fails and leaves the directory at /dev/shm/php-test)

### Actual result
/tmp/php-test is created as an empty file. "read failed: Is a directory" is printed to stderr, but the rename() function returns success. /dev/shm/php-test still exists.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.