From 5d4774491f2e22c763dc045a35f799302d146007 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 21 Dec 2022 00:52:07 +0200 Subject: [PATCH] Exclude macOs fork files from tar processing (#3165) When running tenant relocation tests, we use https://github.com/neondatabase/neon/blob/main/scripts/export_import_between_pageservers.py script to export and import basebackup between pageservers. When pageserver runs on macOs and reuses the `tar` library for creating the basebackup archive, it gets the fork files https://superuser.com/questions/61185/why-do-i-get-files-like-foo-in-my-tarball-on-os-x We might be able to fix our code to fix the issue, but if we get such (valid) archive as an input, we [fail](https://github.com/neondatabase/neon/pull/3013#issuecomment-1360093900). This does not seem optimal, given that we can ignore such files. --- pageserver/src/import_datadir.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pageserver/src/import_datadir.rs b/pageserver/src/import_datadir.rs index 642e41765b..db83bdb3a1 100644 --- a/pageserver/src/import_datadir.rs +++ b/pageserver/src/import_datadir.rs @@ -440,16 +440,22 @@ fn import_file( reader: Reader, len: usize, ) -> Result> { + let file_name = match file_path.file_name() { + Some(name) => name.to_string_lossy(), + None => return Ok(None), + }; + + if file_name.starts_with('.') { + // tar archives on macOs, created without COPYFILE_DISABLE=1 env var + // will contain "fork files", skip them. + return Ok(None); + } + if file_path.starts_with("global") { let spcnode = postgres_ffi::pg_constants::GLOBALTABLESPACE_OID; let dbnode = 0; - match file_path - .file_name() - .expect("missing filename") - .to_string_lossy() - .as_ref() - { + match file_name.as_ref() { "pg_control" => { let bytes = read_all_bytes(reader)?; @@ -485,12 +491,7 @@ fn import_file( .to_string_lossy() .parse()?; - match file_path - .file_name() - .expect("missing base filename") - .to_string_lossy() - .as_ref() - { + match file_name.as_ref() { "pg_filenode.map" => { let bytes = read_all_bytes(reader)?; modification.put_relmap_file(spcnode, dbnode, bytes)?; @@ -520,11 +521,7 @@ fn import_file( import_slru(modification, slru, file_path, reader, len)?; debug!("imported multixact members slru"); } else if file_path.starts_with("pg_twophase") { - let file_name = &file_path - .file_name() - .expect("missing twophase filename") - .to_string_lossy(); - let xid = u32::from_str_radix(file_name, 16)?; + let xid = u32::from_str_radix(file_name.as_ref(), 16)?; let bytes = read_all_bytes(reader)?; modification.put_twophase_file(xid, Bytes::copy_from_slice(&bytes[..]))?;