Tip: Copying files between handles in libguestfs

libguestfs handles are completely independent of each other. There is no function in the API that takes two handles as arguments, still less any function to copy files between handles.

However you can do it by going via the local disk. The code below copies /dir1 from the first handle to /dir2 in the second handle:

g1.tar_out ("/dir1", "/tmp/temp.tar")
g2.tar_in ("/tmp/temp.tar", "/dir2")

In real code you should choose a randomly named temporary file to avoid tmp exploits.

If your handles were managed by separate threads, then you could do this more efficiently without the local disk by using a pipe.


Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.