public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob 10a7ee2a1f0fb14edb8572b43c6e54d1fbb04d8d 921 bytes (raw)
$ git show stable-1.6:lib/PublicInbox/NDC_PP.pm	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
# Copyright (C) 2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# Pure-perl class for Linux non-Inline::C users to disable COW for btrfs
package PublicInbox::NDC_PP;
use strict;
use v5.10.1;

sub nodatacow_dir ($) {
	my ($path) = @_;
	open my $mh, '<', '/proc/self/mounts' or return;
	for (grep(/ btrfs /, <$mh>)) {
		my (undef, $mnt_path, $type) = split(/ /);
		next if $type ne 'btrfs'; # in case of false-positive from grep

		# weird chars are escaped as octal
		$mnt_path =~ s/\\(0[0-9]{2})/chr(oct($1))/egs;
		$mnt_path .= '/' unless $mnt_path =~ m!/\z!;
		if (index($path, $mnt_path) == 0) {
			# error goes to stderr, but non-fatal for us
			system('chattr', '+C', $path);
			last;
		}
	}
}

sub nodatacow_fd ($) {
	my ($fd) = @_;
	return if $^O ne 'linux';
	defined(my $path = readlink("/proc/self/fd/$fd")) or return;
	nodatacow_dir($path);
}

1;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git