Skip to content

Commit 0c7e8f7

Browse files
committed
path2: Remove some API functions
Delete the following API functions: - set_dirname() - with_dirname() - set_filestem() - with_filestem() - add_extension() - file_path() Also change pop() to return a boolean instead of an owned copy of the old filename.
1 parent bab7eb2 commit 0c7e8f7

File tree

8 files changed

+101
-643
lines changed

8 files changed

+101
-643
lines changed

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
164164
Some(s) => Some(Path::new(s)),
165165
None => {
166166
if parse_name_directive(line, "pp-exact") {
167-
testfile.file_path()
167+
testfile.filename().map_move(|s| Path::new(s))
168168
} else {
169169
None
170170
}

src/compiletest/runtest.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,12 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
662662

663663
fn make_exe_name(config: &config, testfile: &Path) -> Path {
664664
let mut f = output_base_name(config, testfile);
665-
f.add_extension(os::EXE_EXTENSION);
665+
if !os::EXE_SUFFIX.is_empty() {
666+
match f.filename().map_move(|s| s + os::EXE_SUFFIX.as_bytes()) {
667+
Some(v) => f.set_filename(v),
668+
None => ()
669+
}
670+
}
666671
f
667672
}
668673

@@ -747,7 +752,10 @@ fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
747752

748753
fn aux_output_dir_name(config: &config, testfile: &Path) -> Path {
749754
let mut f = output_base_name(config, testfile);
750-
f.add_extension("libaux");
755+
match f.filename().map_move(|s| s + bytes!(".libaux")) {
756+
Some(v) => f.set_filename(v),
757+
None => ()
758+
}
751759
f
752760
}
753761

src/librustc/metadata/filesearch.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum FileMatch { FileMatches, FileDoesntMatch }
2424
pub type pick<'self> = &'self fn(path: &Path) -> FileMatch;
2525

2626
pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
27-
if path.file_path() == Some(file) {
27+
if path.filename() == Some(file.as_vec()) {
2828
Some(path.clone())
2929
} else {
3030
None
@@ -206,11 +206,10 @@ pub fn rust_path() -> ~[Path] {
206206
env_rust_path.push(cwd.clone());
207207
}
208208
loop {
209-
let f = cwd.pop();
210-
if f.is_none() || bytes!("..") == f.unwrap() {
211-
break;
209+
if { let f = cwd.filename(); f.is_none() || f.unwrap() == bytes!("..") } {
210+
break
212211
}
213-
cwd.push(".rust");
212+
cwd.set_filename(".rust");
214213
if !env_rust_path.contains(&cwd) && os::path_exists(&cwd) {
215214
env_rust_path.push(cwd.clone());
216215
}

src/librustpkg/path_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ pub fn user_set_rust_path() -> bool {
449449

450450
/// Append the version string onto the end of the path's filename
451451
pub fn versionize(p: &Path, v: &Version) -> Path {
452-
let q = p.file_path().expect("path is a directory");
453-
let mut q = q.as_vec().to_owned();
452+
let q = p.filename().expect("path is a directory");
453+
let mut q = q.to_owned();
454454
q.push('-' as u8);
455455
let vs = v.to_str();
456456
q.push_all(vs.as_bytes());

src/libstd/os.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,9 @@ pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
693693
if path_is_dir(p) {
694694
return true;
695695
}
696-
let mut p_ = p.clone();
697-
if p_.pop().is_some() {
696+
if p.filename().is_some() {
697+
let mut p_ = p.clone();
698+
p_.pop();
698699
if !mkdir_recursive(&p_, mode) {
699700
return false;
700701
}

src/libstd/path/mod.rs

Lines changed: 4 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
268268
self.extension().and_then(str::from_utf8_slice_opt)
269269
}
270270

271-
/// Replaces the directory portion of the path with the given byte vector or string.
272-
/// If `self` represents the root of the filesystem hierarchy, the last path component
273-
/// of the argument becomes the filename.
274-
///
275-
/// # Failure
276-
///
277-
/// Raises the `null_byte` condition if the dirname contains a NUL.
278-
#[inline]
279-
fn set_dirname<T: BytesContainer>(&mut self, dirname: T) {
280-
if contains_nul(dirname.container_as_bytes()) {
281-
let dirname = self::null_byte::cond.raise(dirname.container_into_owned_bytes());
282-
assert!(!contains_nul(dirname));
283-
unsafe { self.set_dirname_unchecked(dirname) }
284-
} else {
285-
unsafe { self.set_dirname_unchecked(dirname) }
286-
}
287-
}
288271
/// Replaces the filename portion of the path with the given byte vector or string.
289272
/// If the replacement name is [], this is equivalent to popping the path.
290273
///
@@ -301,53 +284,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
301284
unsafe { self.set_filename_unchecked(filename) }
302285
}
303286
}
304-
/// Replaces the filestem with the given byte vector or string.
305-
/// If there is no extension in `self` (or `self` has no filename), this is equivalent
306-
/// to `set_filename`. Otherwise, if the argument is [] or "", the extension (including
307-
/// the preceding '.') becomes the new filename.
308-
///
309-
/// # Failure
310-
///
311-
/// Raises the `null_byte` condition if the filestem contains a NUL.
312-
fn set_filestem<T: BytesContainer>(&mut self, filestem: T) {
313-
// borrowck is being a pain here
314-
enum Value<T> {
315-
Checked(T),
316-
Unchecked(~[u8])
317-
}
318-
let val = {
319-
match self.filename() {
320-
None => Checked(filestem),
321-
Some(name) => {
322-
let dot = '.' as u8;
323-
match name.rposition_elem(&dot) {
324-
None | Some(0) => Checked(filestem),
325-
Some(idx) => {
326-
let mut v;
327-
if contains_nul(filestem.container_as_bytes()) {
328-
let filestem = filestem.container_into_owned_bytes();
329-
let filestem = self::null_byte::cond.raise(filestem);
330-
assert!(!contains_nul(filestem));
331-
v = filestem;
332-
let n = v.len();
333-
v.reserve(n + name.len() - idx);
334-
} else {
335-
let filestem = filestem.container_as_bytes();
336-
v = vec::with_capacity(filestem.len() + name.len() - idx);
337-
v.push_all(filestem);
338-
}
339-
v.push_all(name.slice_from(idx));
340-
Unchecked(v)
341-
}
342-
}
343-
}
344-
}
345-
};
346-
match val {
347-
Checked(v) => self.set_filename(v),
348-
Unchecked(v) => unsafe { self.set_filename_unchecked(v) }
349-
}
350-
}
351287
/// Replaces the extension with the given byte vector or string.
352288
/// If there is no extension in `self`, this adds one.
353289
/// If the argument is [] or "", this removes the extension.
@@ -417,61 +353,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
417353
Some(v) => unsafe { self.set_filename_unchecked(v) }
418354
}
419355
}
420-
/// Adds the given extension (as a byte vector or string) to the file.
421-
/// This does not remove any existing extension.
422-
/// `foo.bar`.add_extension(`baz`) becomes `foo.bar.baz`.
423-
/// If `self` has no filename, this is a no-op.
424-
/// If the argument is [] or "", this is a no-op.
425-
///
426-
/// # Failure
427-
///
428-
/// Raises the `null_byte` condition if the extension contains a NUL.
429-
fn add_extension<T: BytesContainer>(&mut self, extension: T) {
430-
if extension.container_as_bytes().is_empty() { return; }
431-
// appease borrowck
432-
let val = {
433-
match self.filename() {
434-
None => None,
435-
Some(name) => {
436-
let mut v;
437-
if contains_nul(extension.container_as_bytes()) {
438-
let ext = extension.container_into_owned_bytes();
439-
let extension = self::null_byte::cond.raise(ext);
440-
assert!(!contains_nul(extension));
441-
v = vec::with_capacity(name.len() + 1 + extension.len());
442-
v.push_all(name);
443-
v.push('.' as u8);
444-
v.push_all(extension);
445-
} else {
446-
let extension = extension.container_as_bytes();
447-
v = vec::with_capacity(name.len() + 1 + extension.len());
448-
v.push_all(name);
449-
v.push('.' as u8);
450-
v.push_all(extension);
451-
}
452-
Some(v)
453-
}
454-
}
455-
};
456-
match val {
457-
None => (),
458-
Some(v) => unsafe { self.set_filename_unchecked(v) }
459-
}
460-
}
461356

462-
/// Returns a new Path constructed by replacing the dirname with the given
463-
/// byte vector or string.
464-
/// See `set_dirname` for details.
465-
///
466-
/// # Failure
467-
///
468-
/// Raises the `null_byte` condition if the dirname contains a NUL.
469-
#[inline]
470-
fn with_dirname<T: BytesContainer>(&self, dirname: T) -> Self {
471-
let mut p = self.clone();
472-
p.set_dirname(dirname);
473-
p
474-
}
475357
/// Returns a new Path constructed by replacing the filename with the given
476358
/// byte vector or string.
477359
/// See `set_filename` for details.
@@ -485,19 +367,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
485367
p.set_filename(filename);
486368
p
487369
}
488-
/// Returns a new Path constructed by setting the filestem to the given
489-
/// byte vector or string.
490-
/// See `set_filestem` for details.
491-
///
492-
/// # Failure
493-
///
494-
/// Raises the `null_byte` condition if the filestem contains a NUL.
495-
#[inline]
496-
fn with_filestem<T: BytesContainer>(&self, filestem: T) -> Self {
497-
let mut p = self.clone();
498-
p.set_filestem(filestem);
499-
p
500-
}
501370
/// Returns a new Path constructed by setting the extension to the given
502371
/// byte vector or string.
503372
/// See `set_extension` for details.
@@ -518,12 +387,6 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
518387
// self.dirname() returns a NUL-free vector
519388
unsafe { GenericPathUnsafe::new_unchecked(self.dirname()) }
520389
}
521-
/// Returns the file component of `self`, as a relative Path.
522-
/// If `self` represents the root of the filesystem hierarchy, returns None.
523-
fn file_path(&self) -> Option<Self> {
524-
// self.filename() returns a NUL-free vector
525-
self.filename().map_move(|v| unsafe { GenericPathUnsafe::new_unchecked(v) })
526-
}
527390

528391
/// Returns a Path that represents the filesystem root that `self` is rooted in.
529392
///
@@ -561,16 +424,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
561424
}
562425
}
563426
}
564-
/// Pops the last path component off of `self` and returns it.
565-
/// If `self` represents the root of the file hierarchy, None is returned.
566-
fn pop(&mut self) -> Option<~[u8]>;
567-
/// Pops the last path component off of `self` and returns it as a string, if possible.
568-
/// `self` will still be modified even if None is returned.
569-
/// See `pop` for details.
570-
#[inline]
571-
fn pop_str(&mut self) -> Option<~str> {
572-
self.pop().and_then(|v| str::from_utf8_owned_opt(v))
573-
}
427+
/// Removes the last path component from the receiver.
428+
/// Returns `true` if the receiver was modified, or `false` if it already
429+
/// represented the root of the file hierarchy.
430+
fn pop(&mut self) -> bool;
574431

575432
/// Returns a new Path constructed by joining `self` with the given path
576433
/// (as a byte vector or string).
@@ -658,11 +515,6 @@ pub trait GenericPathUnsafe {
658515
/// The resulting Path will always be normalized.
659516
unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Self;
660517

661-
/// Replaces the directory portion of the path without checking for null
662-
/// bytes.
663-
/// See `set_dirname` for details.
664-
unsafe fn set_dirname_unchecked<T: BytesContainer>(&mut self, dirname: T);
665-
666518
/// Replaces the filename portion of the path without checking for null
667519
/// bytes.
668520
/// See `set_filename` for details.

0 commit comments

Comments
 (0)