Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Fail with a better error message when list_dir gets an empty path #6687

Merged
merged 2 commits into from
May 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
/// Lists the contents of a directory
#[allow(non_implicitly_copyable_typarams)]
pub fn list_dir(p: &Path) -> ~[~str] {
if p.components.is_empty() && !p.is_absolute() {
// Not sure what the right behavior is here, but this
// prevents a bounds check failure later
return ~[];
}
unsafe {
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
Expand Down Expand Up @@ -1596,6 +1601,26 @@ mod tests {
}
}

#[test]
fn list_dir_empty_path() {
let dirs = os::list_dir(&Path(""));
assert!(dirs.is_empty());
}

#[test]
#[cfg(not(windows))]
fn list_dir_root() {
let dirs = os::list_dir(&Path("/"));
assert!(dirs.len() > 1);
}
#[test]
#[cfg(windows)]
fn list_dir_root() {
let dirs = os::list_dir(&Path("C:\\"));
assert!(dirs.len() > 1);
}


#[test]
fn path_is_dir() {
assert!((os::path_is_dir(&Path("."))));
Expand Down