internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: borgbackup/borg

Issue:
pyinstaller ssh/openssh library loading issue / OpenSSL version mismatch
From the mailing list, reported by cherio:
```
Remote: OpenSSL version mismatch. Built against 1010106f, you have 101000cf
```
It seems issue #514 is there again.
This was observed using `borg-linux64` and `borg-linux64.tgz` 1.1.15 and 1.1.16, but not with 1.1.14.

1.1.14 was last borg built with pyinstaller 3.2.1.
1.1.15 was built with 4.0, 1.1.16 was built with 4.2.

The user uses borg binaries on Ubuntu 20.04. 
```
> openssl version
OpenSSL 1.1.1f  31 Mar 2020

> ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020

> python
Python 3.8.5 (default, May 27 2021, 13:30:53)
[GCC 9.3.0] on linux
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.1.1f  31 Mar 2020'
```
So, system openssl is 1.1.1f, system ssh wants 1.1.1f.
Very likely the pyi bundle has 1.1.0 (for bundled python).

Related borg code:
- https://github.com/borgbackup/borg/blob/1.1.16/src/borg/helpers.py#L2407
- https://github.com/borgbackup/borg/blob/1.1.16/src/borg/remote.py#L553


Discussion:
I think the bug is slightly different than described above (update: cherio confirmed it is only in single-dir mode):

The problem is that LD_LIBRARY_PATH_ORIG is only provided by pyinstaller, if there was a LD_LIBRARY_PATH in the original env. If not, things get complicated:

https://github.com/borgbackup/borg/blob/1.1.16/src/borg/helpers.py#L2426

We check there if the LDLP contains `_MEI`, but that is only the case for the single-file pyi bundle.
For the single-dir bundle, it is just the absolute path of the unpacked bundle (not _MEI temp path).

Workaround for using the single-dir bundle, avoiding the problematic part of the code:
```
LD_LIBRARY_PATH=/invalid borg ... ssh://user@host/repo ...
```
see also there: https://github.com/pyinstaller/pyinstaller/issues/2892

Resolving patch:
diff --git a/src/borg/helpers/process.py b/src/borg/helpers/process.py
--- a/src/borg/helpers/process.py
+++ b/src/borg/helpers/process.py
@@ -290,10 +290,9 @@ def prepare_subprocess_env(system, env=None):
             #    in the original env (in this case, the pyinstaller bootloader
             #    does *not* put ..._ORIG into the env either).
             #    in this case, we must kill LDLP.
-            # The directory used by pyinstaller is created by mkdtemp("_MEIXXXXXX"),
-            # we can use that to differentiate between the cases.
+            #    We can recognize this via sys.frozen and sys._MEIPASS being set.
             lp = env.get(lp_key)
-            if lp is not None and re.search(r'/_MEI......', lp):
+            if lp is not None and getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
                 env.pop(lp_key)
     # security: do not give secrets to subprocess
     env.pop('BORG_PASSPHRASE', None)


Test patch:
Repository: borgbackup/borg

Issue:
require py38 (master branch /  borg 1.2)
considering that there is widespread support for 3.8+ meanwhile and creating the next release (1.2) is still todo, i guess we could also drop support for py37 and require py38 as the minimum for borg >= 1.2.

anyone seeing a problem with this?

everybody who is still on <=py37 seems to prefer older / stable stuff, so can as well just use borg 1.1.x.


Discussion:
I checked all the stuff used by our vagrant testing boxes:
```
boxes using pyenv install 3.9.7 for the binary build and do not use the
system python for testing, but other pythons installed via pyenv.

ubuntu focal: 3.8.2
debian bullseye: 3.9.2
debian buster: pyenv
debian stretch: pyenv
freebsd 12.1: pyenv
openbsd 6.9: 3.8.x
netbsd 9.2: 3.8.x (but box is broken)
macos-sierra: pyenv
openindiana 2021.04: 3.9.4 (currently upgrading that box)
```
Seems like noone has anything against this, so I'll do that now...

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -271,7 +271,6 @@ def members_appended(*ds):
         'Operating System :: POSIX :: Linux',
         'Programming Language :: Python',
         'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: 3.10',
@@ -299,5 +298,5 @@ def members_appended(*ds):
     setup_requires=['setuptools_scm>=1.7'],
     install_requires=install_requires,
     extras_require=extras_require,
-    python_requires='>=3.7',
+    python_requires='>=3.8',
 )
diff --git a/src/borg/helpers/misc.py b/src/borg/helpers/misc.py
--- a/src/borg/helpers/misc.py
+++ b/src/borg/helpers/misc.py
@@ -79,11 +79,7 @@ def sysinfo():
     except AttributeError:
         uname = None
     if sys.platform.startswith('linux'):
-        try:
-            linux_distribution = platform.linux_distribution()  # noqa
-        except:
-            # platform.linux_distribution() is deprecated since py 3.5 and removed in 3.7.
-            linux_distribution = ('Unknown Linux', '', '')
+        linux_distribution = ('Unknown Linux', '', '')
     else:
         linux_distribution = None
     try:


Test patch:
Repository: borgbackup/borg

Issue:
do back/forward ports (63)
https://github.com/borgbackup/borg/issues?utf8=%E2%9C%93&q=label%3Abackport%2F1.1-maint
https://github.com/borgbackup/borg/issues?utf8=%E2%9C%93&q=label%3Aforwardport%2Fmaster

do 2 simple/small or 1 mid-sized/mid-complex forward/backport from there.

---

:moneybag: [there is a bounty for this](https://www.bountysource.com/issues/99635182-do-back-forward-ports-63)


Discussion:

Resolving patch:
diff --git a/src/borg/helpers.py b/src/borg/helpers.py
--- a/src/borg/helpers.py
+++ b/src/borg/helpers.py
@@ -553,15 +553,20 @@ def get_base_dir():
 
 def get_keys_dir():
     """Determine where to repository keys and cache"""
-
-    keys_dir = os.environ.get('BORG_KEYS_DIR', os.path.join(get_config_dir(), 'keys'))
+    keys_dir = os.environ.get('BORG_KEYS_DIR')
+    if keys_dir is None:
+        # note: do not just give this as default to the environment.get(), see issue #5979.
+        keys_dir = os.path.join(get_config_dir(), 'keys')
     ensure_dir(keys_dir)
     return keys_dir
 
 
 def get_security_dir(repository_id=None):
     """Determine where to store local security information."""
-    security_dir = os.environ.get('BORG_SECURITY_DIR', os.path.join(get_config_dir(), 'security'))
+    security_dir = os.environ.get('BORG_SECURITY_DIR')
+    if security_dir is None:
+        # note: do not just give this as default to the environment.get(), see issue #5979.
+        security_dir = os.path.join(get_config_dir(), 'security')
     if repository_id:
         security_dir = os.path.join(security_dir, repository_id)
     ensure_dir(security_dir)


Test patch:
Repository: borgbackup/borg

Issue:
Confusing CLI message "output file to export key to expected"
## 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.17

#### Operating system (distribution) and version.

Pop!_OS 21.10

#### Hardware / network configuration, and filesystems used.

None yet.

#### How much data is handled by borg?

None yet.

#### Full borg commandline that lead to the problem (leave away excludes and passwords)

`borg key export /media/duane/JOHNSONVID2/backup.borg`

## Describe the problem you're observing.

The error message is confusing:
`output file to export key to expected`

Something like this would have been clearer to me:
`please specify the destination file where you'd like the key to be exported`

(Nice to have): In addition, it would be nice if the absence of a file just dumped the key to stdout.




Discussion:
Yeah, sounds like a good suggestion - do you want to make a PR for that?

Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -363,9 +363,6 @@ def do_key_export(self, args, repository):
         if args.paper:
             manager.export_paperkey(args.path)
         else:
-            if not args.path:
-                self.print_error("output file to export key to expected")
-                return EXIT_ERROR
             try:
                 if args.qr:
                     manager.export_qr(args.path)
diff --git a/src/borg/crypto/keymanager.py b/src/borg/crypto/keymanager.py
--- a/src/borg/crypto/keymanager.py
+++ b/src/borg/crypto/keymanager.py
@@ -75,20 +75,29 @@ def get_keyfile_data(self):
         return data
 
     def store_keyfile(self, target):
-        with open(target, 'w') as fd:
+        with dash_open(target, 'w') as fd:
             fd.write(self.get_keyfile_data())
 
     def export(self, path):
+        if path is None:
+            path = '-'
+
         self.store_keyfile(path)
 
     def export_qr(self, path):
-        with open(path, 'wb') as fd:
+        if path is None:
+            path = '-'
+
+        with dash_open(path, 'wb') as fd:
             key_data = self.get_keyfile_data()
             html = pkgutil.get_data('borg', 'paperkey.html')
             html = html.replace(b'</textarea>', key_data.encode() + b'</textarea>')
             fd.write(html)
 
     def export_paperkey(self, path):
+        if path is None:
+            path = '-'
+
         def grouped(s):
             ret = ''
             i = 0
@@ -118,11 +127,8 @@ def grouped(s):
             export += '{0:2d}: {1} - {2}\n'.format(idx, grouped(bin_to_hex(binline)), checksum)
             binary = binary[18:]
 
-        if path:
-            with open(path, 'w') as fd:
-                fd.write(export)
-        else:
-            print(export)
+        with dash_open(path, 'w') as fd:
+            fd.write(export)
 
     def import_keyfile(self, args):
         file_id = KeyfileKey.FILE_ID


Test patch:
Repository: borgbackup/borg

Issue:
master: try msgpack 1.0.3
setup.py currently limits to <= 1.0.2, but 1.0.3 is available since Nov 2021.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -66,7 +66,7 @@
 install_requires = [
     # we are rather picky about msgpack versions, because a good working msgpack is
     # very important for borg, see: https://github.com/borgbackup/borg/issues/3753
-    'msgpack >=0.5.6, <=1.0.2, !=1.0.1',
+    'msgpack >=0.5.6, <=1.0.3, !=1.0.1',
     # Please note:
     # using any other version is not supported by borg development and
     # any feedback related to issues caused by this will be ignored.
diff --git a/src/borg/helpers/msgpack.py b/src/borg/helpers/msgpack.py
--- a/src/borg/helpers/msgpack.py
+++ b/src/borg/helpers/msgpack.py
@@ -182,7 +182,7 @@ def is_slow_msgpack():
 def is_supported_msgpack():
     # DO NOT CHANGE OR REMOVE! See also requirements and comments in setup.py.
     import msgpack
-    return (0, 5, 6) <= msgpack.version <= (1, 0, 2) and \
+    return (0, 5, 6) <= msgpack.version <= (1, 0, 3) and \
            msgpack.version not in [(1, 0, 1), ]  # < add bad releases here to deny list
 
 


Test patch:
Repository: borgbackup/borg

Issue:
it's 2022
check misc. places in source, docs, readme, copyright, license, ... and update to 2022.


Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -40,7 +40,7 @@
 
 # General information about the project.
 project = 'Borg - Deduplicating Archiver'
-copyright = u'2010-2014 Jonas Borgström, 2015-2021 The Borg Collective (see AUTHORS file)'
+copyright = u'2010-2014 Jonas Borgström, 2015-2022 The Borg Collective (see AUTHORS file)'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the


Test patch:
Repository: borgbackup/borg

Issue:
update pypi metadata
master (1.2): alpha -> beta (and keep that at least until 1.2.1)

1.1-maint: definitely beta -> stable

https://pypi.org/classifiers/



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -260,7 +260,7 @@ def members_appended(*ds):
     license='BSD',
     platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ],
     classifiers=[
-        'Development Status :: 3 - Alpha',
+        'Development Status :: 4 - Beta',
         'Environment :: Console',
         'Intended Audience :: System Administrators',
         'License :: OSI Approved :: BSD License',


Test patch:
Repository: borgbackup/borg

Issue:
borg info: No output for empty repo with --last or --first supplied
```
$ borg --version
borg 1.1.17
```

`borg info` or `borg info --json` do not give any output if `--last=1` or `--first=1` is supplied and there are no archives yet.


Discussion:
I'ld assume that if you give last/first=N that then **up to** N items are output (that is less than N if fewer than N archives exist). If 0 archives exist, 0 items are output.

So guess that is correct / consistent behaviour?

`borg info --json` without the `--last=1` gives the following

```json
{
    "cache": {
        "path": "...",
        "stats": {
            "total_chunks": 0,
            "total_csize": 0,
            "total_size": 0,
            "total_unique_chunks": 0,
            "unique_csize": 0,
            "unique_size": 0
        }
    },
    "encryption": {
        "mode": "repokey"
    },
    "repository": {
        "id": "...",
        "last_modified": "2021-10-12T00:03:37.000000",
        "location": "..."
    },
    "security_dir": "..."
}
```

With `--last=1` it returns nothing. Instead I would expect the same output but with `"archives": []` added.
Oh, ok, that makes sense.
also applies to master branch.
The cause of this is that if you invoke do_info for archive(s) (either giving an archive name, last/first or prefix), it calls `_info_archives` while it calls `_info_repository` when only giving the repository.

Also, there is a shortcut in the code if the archives list is empty - I'll remove that.

Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -1391,8 +1391,6 @@ def format_cmdline(cmdline):
         else:
             args.consider_checkpoints = True
             archive_names = tuple(x.name for x in manifest.archives.list_considering(args))
-            if not archive_names:
-                return self.exit_code
 
         output_data = []
 


Test patch:
Repository: borgbackup/borg

Issue:
Confusing CLI message "output file to export key to expected"
## 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.17

#### Operating system (distribution) and version.

Pop!_OS 21.10

#### Hardware / network configuration, and filesystems used.

None yet.

#### How much data is handled by borg?

None yet.

#### Full borg commandline that lead to the problem (leave away excludes and passwords)

`borg key export /media/duane/JOHNSONVID2/backup.borg`

## Describe the problem you're observing.

The error message is confusing:
`output file to export key to expected`

Something like this would have been clearer to me:
`please specify the destination file where you'd like the key to be exported`

(Nice to have): In addition, it would be nice if the absence of a file just dumped the key to stdout.




Discussion:
Yeah, sounds like a good suggestion - do you want to make a PR for that?

Resolving patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -378,9 +378,6 @@ def do_key_export(self, args, repository):
         if args.paper:
             manager.export_paperkey(args.path)
         else:
-            if not args.path:
-                self.print_error("output file to export key to expected")
-                return EXIT_ERROR
             try:
                 if args.qr:
                     manager.export_qr(args.path)
diff --git a/src/borg/crypto/keymanager.py b/src/borg/crypto/keymanager.py
--- a/src/borg/crypto/keymanager.py
+++ b/src/borg/crypto/keymanager.py
@@ -78,20 +78,29 @@ def get_keyfile_data(self):
         return data
 
     def store_keyfile(self, target):
-        with open(target, 'w') as fd:
+        with dash_open(target, 'w') as fd:
             fd.write(self.get_keyfile_data())
 
     def export(self, path):
+        if path is None:
+            path = '-'
+
         self.store_keyfile(path)
 
     def export_qr(self, path):
-        with open(path, 'wb') as fd:
+        if path is None:
+            path = '-'
+
+        with dash_open(path, 'wb') as fd:
             key_data = self.get_keyfile_data()
             html = pkgutil.get_data('borg', 'paperkey.html')
             html = html.replace(b'</textarea>', key_data.encode() + b'</textarea>')
             fd.write(html)
 
     def export_paperkey(self, path):
+        if path is None:
+            path = '-'
+
         def grouped(s):
             ret = ''
             i = 0
@@ -121,11 +130,8 @@ def grouped(s):
             export += '{0:2d}: {1} - {2}\n'.format(idx, grouped(bin_to_hex(binline)), checksum)
             binary = binary[18:]
 
-        if path:
-            with open(path, 'w') as fd:
-                fd.write(export)
-        else:
-            print(export)
+        with dash_open(path, 'w') as fd:
+            fd.write(export)
 
     def import_keyfile(self, args):
         file_id = KeyfileKey.FILE_ID


Test patch:
Repository: borgbackup/borg

Issue:
Confusing "Permission Denied" error message when ~/.config/borg is unreadable
## Have you checked borgbackup docs, FAQ, and open Github issues?

Yes to the latter, no to the prior two b/c even if it's in the docs/FAQ, I think an improvement can be made

## Is this a BUG / ISSUE report or a QUESTION?

Feature Request

## System information. For client/server mode post info for both machines.

#### Your borg version (borg -V).

1.1.17

#### Operating system (distribution) and version.

Ubuntu 20.04

#### Hardware / network configuration, and filesystems used.

Local disk

#### How much data is handled by borg?

N/A

## Describe the problem you're observing.

When borg encounters a configuration directory that is not readable, it errors with a "Permission denied" message.  However, it's not clear what path has permission problems.  The first/obvious, but wrong, assumption is that it's something with the repo directory.  But when you look at that directory, it appears that borg has created a repo (or part of it).

It would be a lot more helpful if the permission denied message included the problematic path that can't be accessed.

```
$ borg init --encryption repokey-blake2 ~/tmp/borg-bar
Enter new passphrase: 
Enter same passphrase again: 
Do you want your passphrase to be displayed for verification? [yN]: n
Error: Permission denied

$ ls -lh ~/.config/borg/
ls: cannot open directory '/home/rsyring/.config/borg/': Permission denied

$ rm -rf ~/.config/borg/
rm: cannot remove '/home/rsyring/.config/borg/': Permission denied

$ sudo rm -rf ~/.config/borg/

$ borg init --encryption repokey-blake2 ~/tmp/borg-bar
A repository already exists at /home/rsyring/tmp/borg-bar.

$ rm -rf ~/tmp/borg-bar/

$ borg init --encryption repokey-blake2 ~/tmp/borg-bar
(...snip... output as expected for successful command)
$
```





Discussion:
I see the issue, not enough information in the error message (which is already a "pretty" error message, not a python traceback).

BTW, to avoid such issues, always run borg as the same user.

If you run borg client/server, always use same user on client, always use same user on server, then you won't run into permission issues.

Ran into this issue myself. I concur, this would be a great quality of life improvement. 
I'll have a look. The path missing in that borg error msg is not helpful.

Resolving patch:
diff --git a/src/borg/helpers/fs.py b/src/borg/helpers/fs.py
--- a/src/borg/helpers/fs.py
+++ b/src/borg/helpers/fs.py
@@ -36,7 +36,7 @@ def ensure_dir(path, mode=stat.S_IRWXU, pretty_deadly=True):
         os.makedirs(path, mode=mode, exist_ok=True)
     except OSError as e:
         if pretty_deadly:
-            raise Error(e.args[1])
+            raise Error(str(e))
         else:
             raise
 


Test patch:
Repository: borgbackup/borg

Issue:
Confusing "Permission Denied" error message when ~/.config/borg is unreadable
## Have you checked borgbackup docs, FAQ, and open Github issues?

Yes to the latter, no to the prior two b/c even if it's in the docs/FAQ, I think an improvement can be made

## Is this a BUG / ISSUE report or a QUESTION?

Feature Request

## System information. For client/server mode post info for both machines.

#### Your borg version (borg -V).

1.1.17

#### Operating system (distribution) and version.

Ubuntu 20.04

#### Hardware / network configuration, and filesystems used.

Local disk

#### How much data is handled by borg?

N/A

## Describe the problem you're observing.

When borg encounters a configuration directory that is not readable, it errors with a "Permission denied" message.  However, it's not clear what path has permission problems.  The first/obvious, but wrong, assumption is that it's something with the repo directory.  But when you look at that directory, it appears that borg has created a repo (or part of it).

It would be a lot more helpful if the permission denied message included the problematic path that can't be accessed.

```
$ borg init --encryption repokey-blake2 ~/tmp/borg-bar
Enter new passphrase: 
Enter same passphrase again: 
Do you want your passphrase to be displayed for verification? [yN]: n
Error: Permission denied

$ ls -lh ~/.config/borg/
ls: cannot open directory '/home/rsyring/.config/borg/': Permission denied

$ rm -rf ~/.config/borg/
rm: cannot remove '/home/rsyring/.config/borg/': Permission denied

$ sudo rm -rf ~/.config/borg/

$ borg init --encryption repokey-blake2 ~/tmp/borg-bar
A repository already exists at /home/rsyring/tmp/borg-bar.

$ rm -rf ~/tmp/borg-bar/

$ borg init --encryption repokey-blake2 ~/tmp/borg-bar
(...snip... output as expected for successful command)
$
```





Discussion:
I see the issue, not enough information in the error message (which is already a "pretty" error message, not a python traceback).

BTW, to avoid such issues, always run borg as the same user.

If you run borg client/server, always use same user on client, always use same user on server, then you won't run into permission issues.

Ran into this issue myself. I concur, this would be a great quality of life improvement. 
I'll have a look. The path missing in that borg error msg is not helpful.

Resolving patch:
diff --git a/src/borg/helpers.py b/src/borg/helpers.py
--- a/src/borg/helpers.py
+++ b/src/borg/helpers.py
@@ -528,7 +528,7 @@ def ensure_dir(path, mode=stat.S_IRWXU, pretty_deadly=True):
         os.makedirs(path, mode=mode, exist_ok=True)
     except OSError as e:
         if pretty_deadly:
-            raise Error(e.args[1])
+            raise Error(str(e))
         else:
             raise
 


Test patch: