I recently had some corruption on my btrfs filesystem, which caused `/var/lib/pacman/local/linux-lts-6.6.28-1/files` to be unreadable:
```
$ ls -l /var/lib/pacman/local/linux-lts-6.6.28-1/files
-rw-r--r-- 1 root root 510300 Apr 23 09:18 /var/lib/pacman/local/linux-lts-6.6.28-1/files
$ cat /var/lib/pacman/local/linux-lts-6.6.28-1/files
cat: /var/lib/pacman/local/linux-lts-6.6.28-1/files: Input/output error
```
However, `pacman -Ql linux-lts` just reports no files in this case and exits with status 0:
```
$ pacman -Ql linux-lts
$ echo $?
0
```
Relevant part of strace output:
```
newfstatat(AT_FDCWD, "/var/lib/pacman/local//linux-lts-6.6.28-1", {st_mode=S_IFDIR|0755, st_size=28, ...}, 0) = 0
getdents64(5, 0x60d95b3864a0 /* 0 entries */, 32768) = 0
close(5) = 0
openat(AT_FDCWD, "/var/lib/pacman/local/linux-lts-6.6.28-1/files", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0644, st_size=510300, ...}) = 0
read(5, 0x60d95b3864b0, 4096) = -1 EIO (Input/output error)
close(5) = 0
ioctl(1, TCGETS, 0x7fff134b4620) = -1 ENOTTY (Inappropriate ioctl for device)
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7a12c8d63770}, NULL, 8) = 0
rt_sigaction(SIGHUP, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7a12c8d63770}, NULL, 8) = 0
rt_sigaction(SIGPIPE, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7a12c8d63770}, NULL, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7a12c8d63770}, NULL, 8) = 0
close(3) = 0
close(4) = 0
exit_group(0) = ?
+++ exited with 0 +++
```
Even a database check doesn't trip over the corruption, despite showing similar I/O errors in strace:
```
$ sudo pacman -Dk
No database errors have been found!
$ echo $?
0
```
In the (highly unlikely) case you don't want to intentionally corrupt your filesystem, the error can be simulated (thanks [StackOverflow](https://stackoverflow.com/a/11362695/14637)) by symlinking the file to `/proc/self/mem` instead, e.g.:
```
$ cd /var/lib/pacman/local/linux-lts-6.6.28-1/
$ sudo mv files files.orig
$ sudo ln -s /proc/self/mem files
```
I wouldn't expect pacman to actually work in the face of a broken filesystem, but it should at least report errors properly. Seems like some read error checking/handling is missing somewhere.
This is the first time in about 10 years of Arch usage that I've found pacman to be any less than 100% robust. It's a dream compared to apt!
↧