Repository: frappe/frappe
Issue: Error during package import

<!--
Welcome to the Frappe Framework issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to Frappe
    - For questions and general support, use https://stackoverflow.com/questions/tagged/frappe
    - For documentation issues, refer to https://frappeframework.com/docs/user/en or the developer cheetsheet https://github.com/frappe/frappe/wiki/Developer-Cheatsheet
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
4. If you think you know what the reason for the bug is, share it with us. Maybe put in a PR 😉
-->

## Description of the issue
Error during package import

## Context information (for bug reports)

**Output of `bench version`**
```
Site on frappecloud
```

## Steps to reproduce the issue

1. Publish the package on the first site
2. Attach the package on the package import on the second site
3. Check "Activate" and "Save"

### Observed result
subprocess.CalledProcessError: Command '['tar', 'xzf', './bee-live.frappe.cloud/private/files/BeeEspRef-0.0.1.tar.gz', '-C', './bee-live.frappe.cloud/packages']' returned non-zero exit status 2.
### Expected result
success import
### Stacktrace / full error message

```
### App Versions
```
{
	"erpnext": "14.27.6",
	"frappe": "14.39.0",
	"hrms": "14.4.3",
	"payments": "0.0.1"
}
```
### Route
```
Form/Package Import/Package Import at 2023-06-21 11:41:47.665001
```
### Traceback
```
Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 66, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 47, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1608, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 28, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 305, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 339, in _save
    self.run_before_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1045, in run_before_save_methods
    self.run_method("validate")
  File "apps/frappe/frappe/model/document.py", line 914, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1264, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1246, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 911, in fn
    return method_object(*args, **kwargs)
  File "apps/frappe/frappe/core/doctype/package_import/package_import.py", line 18, in validate
    self.import_package()
  File "apps/frappe/frappe/core/doctype/package_import/package_import.py", line 34, in import_package
    subprocess.check_output(
  File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['tar', 'xzf', './bee-live.frappe.cloud/private/files/bee_esp_ref-0.0.1.tar.gz', '-C', './bee-live.frappe.cloud/packages']' returned non-zero exit status 2.

```
### Request Data
```
{
	"type": "POST",
	"args": {
		"doc": "{\\"name\\":\\"Package Import at 2023-06-21 11:19:06.269268\\",\\"owner\\":\\"jiri.sir@xx.com\\",\\"creation\\":\\"2023-06-21 11:19:06.269268\\",\\"modified\\":\\"2023-06-21 11:20:51.497539\\",\\"modified_by\\":\\"jiri.sir@xx.com\\",\\"docstatus\\":0,\\"idx\\":0,\\"attach_package\\":\\"\\",\\"activate\\":1,\\"force\\":0,\\"doctype\\":\\"Package Import\\",\\"__last_sync_on\\":\\"2023-06-21T09:24:36.341Z\\",\\"__unsaved\\":1}",
		"action": "Save"
	},
	"btn": {
		"jQuery360035348907895378591": {
			"events": {
				"click": [
					{
						"type": "click",
						"origType": "click",
						"guid": 2381,
						"namespace": ""
					}
				]
			}
		}
	},
	"freeze": true,
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.desk.form.save.savedocs"
}
```
### Response Data
```
{
	"exception": "subprocess.CalledProcessError: Command '['tar', 'xzf', './bee-live.frappe.cloud/private/files/bee_esp_ref-0.0.1.tar.gz', '-C', './bee-live.frappe.cloud/packages']' returned non-zero exit status 2."
}
```
```

## Additional information

OS version / distribution, `Frappe` install method, etc.


Changed files:
frappe/core/doctype/package_import/package_import.py

diff --git a/frappe/core/doctype/package_import/package_import.py b/frappe/core/doctype/package_import/package_import.py
index 4939b357b0..25288603e1 100644
--- a/frappe/core/doctype/package_import/package_import.py
+++ b/frappe/core/doctype/package_import/package_import.py
@@ -10,6 +10,7 @@ from frappe.desk.form.load import get_attachments
 from frappe.model.document import Document
 from frappe.model.sync import get_doc_files
 from frappe.modules.import_file import import_doc, import_file_by_path
+from frappe.utils import get_files_path
 
 
 class PackageImport(Document):
@@ -35,7 +36,7 @@ class PackageImport(Document):
 			[
 				"tar",
 				"xzf",
-				frappe.get_site_path(attachment.file_url.strip("/")),
+				get_files_path(attachment.file_name, is_private=attachment.is_private),
 				"-C",
 				frappe.get_site_path("packages"),
 			]