Repository: borgbackup/borg

Issue:
attrs: [Errno 1] Operation not permitted: '<FD 7>'
<!--
Thank you for reporting an issue.

*IMPORTANT* -  *before* creating a new issue please look around:
 - Borgbackup documentation: http://borgbackup.readthedocs.io/en/stable/index.html
 - FAQ: https://borgbackup.readthedocs.io/en/stable/faq.html
 and
 - open issues in Github tracker: https://github.com/borgbackup/borg/issues
  
If you cannot find a similar problem, then create a new issue.

Please fill in as much of the template as possible.
-->

## Have you checked borgbackup docs, FAQ, and open Github issues?

Yes

## Is this a BUG / ISSUE report or a QUESTION?

Issue

## System information. For client/server mode post info for both machines.

#### Your borg version (borg -V).
borg 1.1.9 on the server being backed up
borg 1.1.7 on the server with the remote repository

#### Operating system (distribution) and version.
centos 7 on the server being backed up
Linux synology on the server with the remote repository

#### Hardware / network configuration, and filesystems used.
ext4 on both

#### How much data is handled by borg?
16 GB original size

#### Full borg commandline that lead to the problem (leave away excludes and passwords)
`borg extract /path/to/repo::my-files home/USERNAME/src`

## Describe the problem you're observing.
I run the above command to extract some files from a certain path and I get the error
```
attrs: [Errno 1] Operation not permitted: '<FD 7>'
```
Even though I see the error when extracting, I check the file afterwards and it has been extracted and the size is normal. Then why do I see this error? Could it mean that the file is corrupted?

#### Can you reproduce the problem? If so, describe how. If not, describe troubleshooting steps you took before opening the issue.
I run `borg create` on the centos server. The repository is remote on the synology. The backup run succesfully. Then when I am extracting on synology, I see the error.

#### Include any warning/errors/backtraces from the system logs
No logs on synology.
<!--

If this complaint relates to borg performance, please include CRUD benchmark
results and any steps you took to troubleshoot.
How to run benchmark: http://borgbackup.readthedocs.io/en/stable/usage/benchmark.html

*IMPORTANT* - Please mark logs and text output from terminal commands 
or else Github will not display them correctly. 
An example is provided below.

Example:
```
this is an example how log text should be marked (wrap it with ```)
```
-->



Discussion:
try to reproduce with a current borg version (to which you want to upgrade anyway, see changelog).

also try as root.

"attrs" means that it happens when trying to set xattrs (or ACLs or selinux stuff). That needs to be supported by your filesystem to work.
I got this too. Running 1.1.11 everywhere and backup to Borgbase.

Backup is created on a Centos 7 with SELinux set to enforcing.

I tested by running a borg docker image on my docker-for-mac (also 1.1.11) and against the same borgbase remote.

When I ran the same restore command on the Centos 7 host, no errors were given. File was always extracted OK, regardles of the env/error.
> "attrs" means that it happens when trying to set xattrs (or ACLs or selinux stuff). That needs to be supported by your filesystem to work.

Oh. Could it be possible to detect this in Borg code and maybe tell the user that some attrs couldn't be restored, and the usual culprit being that current fs not supporting some attrs.

It also threw me off for a while, I tought the extract command had errored, especially when it says Errno 1 and not warning. Error means non-recoverable usually. I only checked if the file was extracted when someone in one of these issues mentioned that the file did extract OK.
True, I restored a backup and even though each and every file had this Error, the restored backup was complete.
a general thing to check/improve here: it refers to an FD number, does it also show the filename? if not, we should find some way to do that. this is especially an issue in master branch, where a lot of stuff happens based on the FD (and not the filename).
Indeed it shows the full path and filename before the `[Errno 1] Operation not permitted: '<FD num>'`

Resolving patch:
diff --git a/src/borg/archive.py b/src/borg/archive.py
--- a/src/borg/archive.py
+++ b/src/borg/archive.py
@@ -770,28 +770,23 @@ def restore_attrs(self, path, item, symlink=False, fd=None):
             try:
                 xattr.setxattr(fd or path, k, v, follow_symlinks=False)
             except OSError as e:
+                msg_format = '%s: when setting extended attribute %s: %%s' % (path, k.decode())
                 if e.errno == errno.E2BIG:
-                    # xattr is too big
-                    logger.warning('%s: Value or key of extended attribute %s is too big for this filesystem' %
-                                   (path, k.decode()))
-                    set_ec(EXIT_WARNING)
+                    err_str = 'too big for this filesystem'
                 elif e.errno == errno.ENOTSUP:
-                    # xattrs not supported here
-                    logger.warning('%s: Extended attributes are not supported on this filesystem' % path)
-                    set_ec(EXIT_WARNING)
-                elif e.errno == errno.EACCES:
-                    # permission denied to set this specific xattr (this may happen related to security.* keys)
-                    logger.warning('%s: Permission denied when setting extended attribute %s' % (path, k.decode()))
-                    set_ec(EXIT_WARNING)
+                    err_str = 'xattrs not supported on this filesystem'
                 elif e.errno == errno.ENOSPC:
                     # no space left on device while setting this specific xattr
                     # ext4 reports ENOSPC when trying to set an xattr with >4kiB while ext4 can only support 4kiB xattrs
                     # (in this case, this is NOT a "disk full" error, just a ext4 limitation).
-                    logger.warning('%s: No space left on device while setting extended attribute %s (len = %d)' % (
-                        path, k.decode(), len(v)))
-                    set_ec(EXIT_WARNING)
+                    err_str = 'no space left on device [xattr len = %d]' % (len(v), )
                 else:
-                    raise
+                    # generic handler
+                    # EACCES: permission denied to set this specific xattr (this may happen related to security.* keys)
+                    # EPERM: operation not permitted
+                    err_str = str(e)
+                logger.warning(msg_format % err_str)
+                set_ec(EXIT_WARNING)
         # bsdflags include the immutable flag and need to be set last:
         if not self.nobsdflags and 'bsdflags' in item:
             try:


Test patch: