Skip to content

Commit 9058388

Browse files
Soufiane JounaidSoufiane Jounaid
authored andcommitted
Fix to container.upload()'s behavior
container.upload() previously only uploaded the contents of a specified directory path to the container. It now uploads the file or directory pointed to by the specified path. Example before: container.upload(test.png) would not upload the file as it would need a directory path. Example before: container.upload(test/) would upload the contents of the test directory Example after: container.upload(test.png) uploads the file test.png and container.upload(test/) uploads the entire test directory
1 parent a83d9e1 commit 9058388

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

chi/container.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import io
16+
import os
1617
import logging
1718
import tarfile
1819
import time
@@ -202,14 +203,17 @@ def execute(container_ref: "str", command: "str") -> "dict":
202203
def upload(container_ref: "str", source: "str", dest: "str") -> "dict":
203204
"""Upload a file or directory to a running container.
204205
206+
This method requires your running container to include
207+
the GNU tar utility.
208+
205209
Args:
206210
container_ref (str): The name or ID of the container.
207211
source (str): The (local) path to the file or directory to upload.
208212
dest (str): The (container) path to upload the file or directory to.
209213
"""
210214
fd = io.BytesIO()
211215
with tarfile.open(fileobj=fd, mode="w") as tar:
212-
tar.add(source, arcname=".")
216+
tar.add(source, arcname=os.path.basename(source))
213217
fd.seek(0)
214218
data = fd.read()
215219
fd.close()
@@ -219,6 +223,9 @@ def upload(container_ref: "str", source: "str", dest: "str") -> "dict":
219223
def download(container_ref: "str", source: "str", dest: "str"):
220224
"""Download a file or directory from a running container.
221225
226+
This method requires your running container to include
227+
both the POSIX sh and GNU tar utilities.
228+
222229
Args:
223230
container_ref (str): The name or ID of the container.
224231
source (str): The (container) path of the file or directory.

0 commit comments

Comments
 (0)