diff options
| author | bors <bors@rust-lang.org> | 2013-05-25 21:16:57 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-25 21:16:57 -0700 |
| commit | 510d0f221c5a9ca7671149fe7e7bb802592edc06 (patch) | |
| tree | bf131318c46711e6e779445bc518f5ec65760d10 /src/libstd | |
| parent | e2f8b51dc599cf1fb7f3f72252bef5e5b717f6bd (diff) | |
| parent | a243ea39c3c155ada813c129081772ede8bce3e4 (diff) | |
| download | rust-510d0f221c5a9ca7671149fe7e7bb802592edc06.tar.gz rust-510d0f221c5a9ca7671149fe7e7bb802592edc06.zip | |
auto merge of #6687 : catamorphism/rust/list_dir_empty, r=catamorphism
r? @brson (Yes, this did happen in real life...)
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/os.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a82f1c98916..44acdd4d617 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -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")] @@ -1597,6 +1602,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(".")))); assert!((!os::path_is_dir(&Path("test/stdtest/fs.rs")))); |
