Skip to content

Commit

Permalink
Added is_restricted() to path
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 19, 2013
1 parent b07eab5 commit c77c5c4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/libcore/path.rs
Expand Up @@ -65,6 +65,7 @@ pub trait GenericPath {
pure fn pop() -> Self;

pure fn unsafe_join((&Self)) -> Self;
pure fn is_restricted() -> bool;

pure fn normalize() -> Self;
}
Expand Down Expand Up @@ -496,6 +497,10 @@ impl GenericPath for PosixPath {
}
}

pure fn is_restricted() -> bool {
false
}

pure fn push_many(cs: &[~str]) -> PosixPath {
let mut v = copy self.components;
for cs.each |e| {
Expand Down Expand Up @@ -738,6 +743,19 @@ impl GenericPath for WindowsPath {
}
}

pure fn is_restricted() -> bool {
match self.filestem() {
Some(stem) => {
match stem.to_lower() {
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
_ => false
}
},
None => false
}
}

pure fn push_many(cs: &[~str]) -> WindowsPath {
let mut v = copy self.components;
for cs.each |e| {
Expand Down Expand Up @@ -1094,4 +1112,12 @@ mod tests {
.normalize()),
"C:\\foo");
}

#[test]
fn test_windows_path_restrictions() {
assert WindowsPath("hi").is_restricted() == false;
assert WindowsPath("C:\\NUL").is_restricted() == true;
assert WindowsPath("C:\\COM1.TXT").is_restricted() == true;
assert WindowsPath("c:\\prn.exe").is_restricted() == true;
}
}

9 comments on commit c77c5c4

@graydon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@kud1ing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "restricted" mean in this context?

@huonw
Copy link
Member

@huonw huonw commented on c77c5c4 Feb 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like they are device files, so maybe that is a better term. (Although "restricted" isn't so bad, since they are illegal filenames in windows.)

@kud1ing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, maybe we should add some documentation here.
Since this seems to be Windows-specific, should this be made available only on Windows?

@bors
Copy link
Contributor

@bors bors commented on c77c5c4 Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism
at mitsuhiko@c77c5c4

@bors
Copy link
Contributor

@bors bors commented on c77c5c4 Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging mitsuhiko/rust/make-absolute-refactor = c77c5c4 into auto

@bors
Copy link
Contributor

@bors bors commented on c77c5c4 Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mitsuhiko/rust/make-absolute-refactor = c77c5c4 merged ok, testing candidate = 0ded562

@bors
Copy link
Contributor

@bors bors commented on c77c5c4 Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c77c5c4 Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 0ded562

Please sign in to comment.