canonical / pylxd

Python module for LXD
https://pylxd.readthedocs.io/en/latest/
Apache License 2.0
256 stars 135 forks source link

recursive_get doesn't preserve permissions #549

Open Guillaumebeuzeboc opened 1 year ago

Guillaumebeuzeboc commented 1 year ago

I noticed that the method recursive_get doesn't seem to preserve permissions. On the contrary, lxc file pull appears to preserve permission.

To reproduce: test.py:

#!/usr/bin/python3

from pylxd import Client

lxd_client = Client()

config = {
    'name': 'helloworld',
    'source': {
        'type': 'image',
        'protocol': 'simplestreams',
        'server': 'https://images.linuxcontainers.org',
        'alias': 'ubuntu/jammy/cloud/amd64',
    },
}

instance = lxd_client.instances.create(config, wait=True)
instance.start(wait=True)
instance.execute(['touch', '/hello-world'])
instance.execute(['chmod', '+x', '/hello-world'])

instance.files.recursive_get('/hello-world', 'hello-world')

then run:

$ python3 test.py
$ ls -l hello-world
-rw-rw-r-- 1 guillaume guillaume 0 juin  30 17:24 hello-world
$ lxc file pull --recursive helloworld/hello-world hello-world-2
$ ls -l hello-world-2                                                                       
-rwxr-xr-x 1 guillaume guillaume 0 juin  30 17:25 hello-world-2

We can see that the lxc file pull kept the execution permission while the recursive_get didn't


pylxd version: 2.3.2a0 lxc version: 5.15

Guillaumebeuzeboc commented 1 year ago

I solved it in my project by reimplementing recursive_get: https://github.com/canonical/colcon-in-container/blob/main/colcon_in_container/providers/lxd.py#L110:L129