Make the ct_* file wrapper functions ignore files for which a file named .pve-ignore.$name exists. ---
This uses a .pve-ignore prefix. Another option would be a suffix. I'm not sure which is better, but personally I like to keep annoying files like that "hidden" from my standard view. src/PVE/LXC/Setup/Base.pm | 22 ++++++++++++++++++++++ src/test/test-debian-012/etc/.pve-ignore.hosts | 0 src/test/test-debian-012/etc/hosts | 2 ++ src/test/test-debian-012/etc/hosts.exp | 2 ++ 4 files changed, 26 insertions(+) create mode 100644 src/test/test-debian-012/etc/.pve-ignore.hosts create mode 100644 src/test/test-debian-012/etc/hosts create mode 100644 src/test/test-debian-012/etc/hosts.exp diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm index 1490578..83bad3e 100644 --- a/src/PVE/LXC/Setup/Base.pm +++ b/src/PVE/LXC/Setup/Base.pm @@ -10,6 +10,7 @@ use Encode; use Fcntl; use File::Path; use File::Spec; +use File::Basename; use PVE::INotify; use PVE::Tools; @@ -446,10 +447,25 @@ sub post_create_hook { # File access wrappers for container setup code. # For user-namespace support these might need to take uid and gid maps into account. +sub ct_is_file_ignored { + my ($self, $file) = @_; + my ($name, $path) = fileparse($file); + return -f "$path/.pve-ignore.$name"; +} + +sub ct_filter_ignored_files { + my $self = shift; + grep { !$self->ct_is_file_ignored($_) } @_; +} + sub ct_reset_ownership { my ($self, @files) = @_; my $conf = $self->{conf}; return if !$self->{id_map}; + + @files = $self->ct_filter_ignored_files(@files); + return if !@files; + my $uid = $self->{rootuid}; my $gid = $self->{rootgid}; chown($uid, $gid, @files); @@ -468,12 +484,14 @@ sub ct_mkdir { sub ct_unlink { my ($self, @files) = @_; foreach my $file (@files) { + next if $self->ct_is_file_ignored($file); CORE::unlink($file); } } sub ct_rename { my ($self, $old, $new) = @_; + return if $self->ct_is_file_ignored($new); CORE::rename($old, $new); } @@ -486,6 +504,7 @@ sub ct_open_file_read { sub ct_open_file_write { my $self = shift; my $file = shift; + $file = '/dev/null' if $self->ct_is_file_ignored($file); my $fh = IO::File->new($file, O_WRONLY | O_CREAT, @_); $self->ct_reset_ownership($fh); return $fh; @@ -507,6 +526,7 @@ sub ct_make_path { sub ct_symlink { my ($self, $old, $new) = @_; + return if $self->ct_is_file_ignored($new); return CORE::symlink($old, $new); } @@ -552,6 +572,7 @@ sub ct_file_get_contents { sub ct_file_set_contents { my ($self, $file, $data, $perms) = @_; + return if $self->ct_is_file_ignored($file); PVE::Tools::file_set_contents($file, $data, $perms); $self->ct_reset_ownership($file); } @@ -560,6 +581,7 @@ sub ct_file_set_contents { # Optionally if the file becomes empty it will be deleted. sub ct_modify_file { my ($self, $file, $data, %options) = @_; + return if $self->ct_is_file_ignored($file); my $head = "# --- BEGIN PVE ---\n"; my $tail = "# --- END PVE ---\n"; diff --git a/src/test/test-debian-012/etc/.pve-ignore.hosts b/src/test/test-debian-012/etc/.pve-ignore.hosts new file mode 100644 index 0000000..e69de29 diff --git a/src/test/test-debian-012/etc/hosts b/src/test/test-debian-012/etc/hosts new file mode 100644 index 0000000..6e62c35 --- /dev/null +++ b/src/test/test-debian-012/etc/hosts @@ -0,0 +1,2 @@ +This is my hosts file. +And you're not allowed to change it! diff --git a/src/test/test-debian-012/etc/hosts.exp b/src/test/test-debian-012/etc/hosts.exp new file mode 100644 index 0000000..6e62c35 --- /dev/null +++ b/src/test/test-debian-012/etc/hosts.exp @@ -0,0 +1,2 @@ +This is my hosts file. +And you're not allowed to change it! -- 2.1.4 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel