Skip to content
Snippets Groups Projects
Commit 51911d75 authored by Dylan Aïssi's avatar Dylan Aïssi
Browse files

Drop patches included in upstream release


Signed-off-by: default avatarDylan Aïssi <dylan.aissi@collabora.com>
parent 97c75b12
Branches apertis/v2022dev3
Tags apertis/0.0.6-1_exp1+apertis5
1 merge request!20Update from debian/bookworm for apertis/v2024dev2
Pipeline #540963 failed
From: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Date: Mon, 7 Jun 2021 18:13:06 +0200
Subject: HACK tr: add limited support for uppercase<->lowercase conversion
`tr` doesn't support character classes for now, however we need limited
support as `pam-auth-update` uses `tr` for performing uppercase ->
lowercase conversion.
This patch adds a quick hack in order to support `[:upper:]` and
`[:lower:]` character classes by substituting those with the
corresponding character range.
This is a "good enough" solution for the purpose of building Apertis
images based on `rust-coreutils` but is not suitable for upstreaming as
it has several drawbacks:
- this approach cannot be used for other character classes
- non-ASCII characters are ignored
Signed-off-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Forwarded: not-needed
Bug: https://github.com/uutils/coreutils/issues/556
---
src/uu/tr/src/expand.rs | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
--- a/src/uu/tr/src/expand.rs
+++ b/src/uu/tr/src/expand.rs
@@ -9,6 +9,7 @@
// spell-checker:ignore (ToDO) allocs slen unesc
+use std::borrow::Cow;
use std::char::from_u32;
use std::cmp::min;
use std::iter::Peekable;
@@ -59,7 +60,22 @@
}
struct Unescape<'a> {
- string: &'a str,
+ string: Cow<'a, str>,
+}
+
+impl<'a> Unescape<'a> {
+ #[inline]
+ pub fn new(s: &'a str) -> Unescape<'a> {
+ let string = if s.contains("[:upper:]") || s.contains("[:lower:]") {
+ s.replace("[:upper:]", "A-Z")
+ .replace("[:lower:]", "a-z")
+ .into()
+ } else {
+ s.into()
+ };
+
+ Unescape { string }
+ }
}
impl<'a> Iterator for Unescape<'a> {
@@ -89,7 +105,11 @@
c => (Some(c), c.len_utf8()), // not an escape char
};
- self.string = &self.string[idx..]; // advance the pointer to the next char
+ // advance the pointer to the next char
+ self.string = match &mut self.string {
+ Cow::Borrowed(s) => s[idx..].into(),
+ Cow::Owned(ref mut s) => s.split_off(idx).into(),
+ };
ret
}
}
@@ -140,7 +160,7 @@
pub fn new(s: &'a str) -> ExpandSet<'a> {
ExpandSet {
range: 0..=0,
- unesc: Unescape { string: s }.peekable(),
+ unesc: Unescape::new(s).peekable(),
}
}
}
From: Ryan Gonzalez <ryan.gonzalez@collabora.com>
Date: Tue, 8 Feb 2022 19:37:55 -0600
Subject: cp: Avoid following a destination symlink with -P
Previously, given 'cp -P a b', where 'a' and 'b' were both symlinks, cp
would end up replacing the target of 'b'.
Forwarded: https://github.com/uutils/coreutils/pull/3101
Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
---
src/uu/cp/src/cp.rs | 52 +++++++++++++++++++++++++++++++++++++++++-------
tests/by-util/test_cp.rs | 46 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+), 7 deletions(-)
diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs
index e01fb60..c9d64dc 100644
--- a/src/uu/cp/src/cp.rs
+++ b/src/uu/cp/src/cp.rs
@@ -1230,7 +1230,8 @@ fn handle_existing_dest(source: &Path, dest: &Path, options: &Options) -> CopyRe
}
/// Copy the a file from `source` to `dest`. `source` will be dereferenced if
-/// `options.dereference` is set to true. `dest` will always be dereferenced.
+/// `options.dereference` is set to true. `dest` will be dereferenced only if
+/// the source was not a symlink.
///
/// Behavior when copying to existing files is contingent on the
/// `options.overwrite` mode. If a file is skipped, the return type
@@ -1280,13 +1281,28 @@ fn copy_file(
let context = context.as_str();
// canonicalize dest and source so that later steps can work with the paths directly
- let dest = canonicalize(dest, MissingHandling::Missing, ResolveMode::Physical).unwrap();
let source = if options.dereference {
canonicalize(source, MissingHandling::Missing, ResolveMode::Physical).unwrap()
} else {
source.to_owned()
};
+ let source_is_symlink = fs::symlink_metadata(&source)
+ .context(context)?
+ .file_type()
+ .is_symlink();
+ let dest_already_exists_as_symlink = fs::symlink_metadata(&dest)
+ .map(|meta| meta.file_type().is_symlink())
+ .unwrap_or(false);
+
+ let dest = if !(source_is_symlink && dest_already_exists_as_symlink) {
+ canonicalize(dest, MissingHandling::Missing, ResolveMode::Physical).unwrap()
+ } else {
+ // Don't canonicalize a symlink copied over another symlink, because
+ // then we'll end up overwriting the destination's target.
+ dest.to_path_buf()
+ };
+
let dest_permissions = if dest.exists() {
dest.symlink_metadata().context(context)?.permissions()
} else {
@@ -1315,7 +1331,14 @@ fn copy_file(
fs::hard_link(&source, &dest).context(context)?;
}
CopyMode::Copy => {
- copy_helper(&source, &dest, options, context, symlinked_files)?;
+ copy_helper(
+ &source,
+ &dest,
+ options,
+ context,
+ source_is_symlink,
+ symlinked_files,
+ )?;
}
CopyMode::SymLink => {
symlink_file(&source, &dest, context, symlinked_files)?;
@@ -1331,10 +1354,24 @@ fn copy_file(
if src_time <= dest_time {
return Ok(());
} else {
- copy_helper(&source, &dest, options, context, symlinked_files)?;
+ copy_helper(
+ &source,
+ &dest,
+ options,
+ context,
+ source_is_symlink,
+ symlinked_files,
+ )?;
}
} else {
- copy_helper(&source, &dest, options, context, symlinked_files)?;
+ copy_helper(
+ &source,
+ &dest,
+ options,
+ context,
+ source_is_symlink,
+ symlinked_files,
+ )?;
}
}
CopyMode::AttrOnly => {
@@ -1373,19 +1410,20 @@ fn copy_helper(
dest: &Path,
options: &Options,
context: &str,
+ source_is_symlink: bool,
symlinked_files: &mut HashSet<FileInformation>,
) -> CopyResult<()> {
if options.parents {
let parent = dest.parent().unwrap_or(dest);
fs::create_dir_all(parent)?;
}
- let is_symlink = fs::symlink_metadata(&source)?.file_type().is_symlink();
+
if source.as_os_str() == "/dev/null" {
/* workaround a limitation of fs::copy
* https://github.com/rust-lang/rust/issues/79390
*/
File::create(dest).context(dest.display().to_string())?;
- } else if is_symlink {
+ } else if source_is_symlink {
copy_link(source, dest, symlinked_files)?;
} else if options.reflink_mode != ReflinkMode::Never {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs
index b2a6eed..07ed05f 100644
--- a/tests/by-util/test_cp.rs
+++ b/tests/by-util/test_cp.rs
@@ -29,6 +29,7 @@ static TEST_EXISTING_FILE: &str = "existing_file.txt";
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
static TEST_HELLO_WORLD_SOURCE_SYMLINK: &str = "hello_world.txt.link";
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
+static TEST_HELLO_WORLD_DEST_SYMLINK: &str = "copy_of_hello_world.txt.link";
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
@@ -657,6 +658,51 @@ fn test_cp_no_deref() {
assert_eq!(at.read(path_to_check), "Hello, World!\n");
}
+#[test]
+fn test_cp_no_deref_link_onto_link() {
+ let (at, mut ucmd) = at_and_ucmd!();
+
+ at.copy(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_DEST);
+
+ #[cfg(not(windows))]
+ let _r = fs::symlink(
+ TEST_HELLO_WORLD_SOURCE,
+ at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
+ );
+ #[cfg(windows)]
+ let _r = symlink_file(
+ TEST_HELLO_WORLD_SOURCE,
+ at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
+ );
+
+ #[cfg(not(windows))]
+ let _r = fs::symlink(
+ TEST_HELLO_WORLD_DEST,
+ at.subdir.join(TEST_HELLO_WORLD_DEST_SYMLINK),
+ );
+ #[cfg(windows)]
+ let _r = symlink_file(
+ TEST_HELLO_WORLD_DEST,
+ at.subdir.join(TEST_HELLO_WORLD_DEST_SYMLINK),
+ );
+
+ ucmd.arg("-P")
+ .arg(TEST_HELLO_WORLD_SOURCE_SYMLINK)
+ .arg(TEST_HELLO_WORLD_DEST_SYMLINK)
+ .succeeds();
+
+ // Ensure that the target of the destination was not modified.
+ assert!(!at
+ .symlink_metadata(TEST_HELLO_WORLD_DEST)
+ .file_type()
+ .is_symlink());
+ assert!(at
+ .symlink_metadata(TEST_HELLO_WORLD_DEST_SYMLINK)
+ .file_type()
+ .is_symlink());
+ assert_eq!(at.read(TEST_HELLO_WORLD_DEST_SYMLINK), "Hello, World!\n");
+}
+
#[test]
fn test_cp_strip_trailing_slashes() {
let (at, mut ucmd) = at_and_ucmd!();
......@@ -32,6 +32,4 @@ relax-binary-heap-plus.diff
unbreak-s390x.patch
# Apertis patches
apertis/HACK-tr-add-limited-support-for-uppercase-lowercase.patch
apertis/HACK-cp-mv-ls-add-dummy-missing-arguments.patch
apertis/cp-Avoid-following-a-destination-symlink-with-P.patch
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment