[Fixed] Issue with IGuestSession.CopyFileToGuest

Discussion about using the VirtualBox API, Tutorials, Samples.

[Fixed] Issue with IGuestSession.CopyFileToGuest

Postby Magnus Madsen » 23. Nov 2017, 15:41

Hi!

I'm seeing some odd behaviour with regards to the CopyFileToGuest function. It seems a change was made in VirtualBox 5.1, that broke the support for copying a file to the guest in the following case:

[*] The destination is a file name, not a folder name.
[*] The destination file does not already exists in the Guest.

In this case the copy operation fails and the file isn't copied to the guest. If the destination is a directory rather than a file name, then the file is copied with no problems. The file is also overwritten successfully if it already exists.

Examples that fail:
[*] Source = "C:\filename.txt", Destination = "C:\filename.txt" - Unless a directory named "C:\filename.txt" exists in which case the file will be copied as "C:\filename.txt\filename.txt" in the guest, or unless the file already exists in the guest in which case it will be overwritten successfully.

I believe the error lies in https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp#L336 around line 336.

The code looks to attempt to see if the destination already exists, and if it is a file or a directory - but something goes wrong.

I think the problem is that if no directory or file with the output name exists, the rc variable is set to an error condition which then prevents the execution of vbox_cat on line 363.

Let me know if I should post this to the vbox_dev list instead, and if any more information would be useful :)
Last edited by socratis on 4. May 2018, 21:07, edited 1 time in total.
Reason: Marked as [Fixed].
Magnus Madsen
 
Posts: 21
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: Issue with IGuestSession.CopyFileToGuest

Postby noteirak » 23. Nov 2017, 15:44

Could you give a piece of standalone code to reproduce the issue first please? And other listed points in the Posting Guidelines
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Issue with IGuestSession.CopyFileToGuest

Postby Magnus Madsen » 23. Nov 2017, 16:20

Yes, of course, sorry for not providing sufficient information!

VirtualBox version: 5.2.0
API: 5.2
MSCOM
C#
Windows 10 host, Windows 7 guest (although any Windows guest OS I've tried does the same)

Code: Select all   Expand viewCollapse view
    public static class VirtualBoxCopyTest
    {
        public static void Run()
        {
            VirtualBox.VirtualBox vb = new VirtualBoxClass();

            IMachine machine = vb.FindMachine("machineName");

            Session session = new Session();

            machine.LockMachine(session, LockType.LockType_Shared);

            while (session.State != SessionState.SessionState_Locked
                && machine.SessionState != SessionState.SessionState_Locked)
            {
                Thread.Sleep(0);
            }

            IGuestSession guestSession = session.Console.Guest.CreateSession("username", "password", "", "testSession");

            GuestSessionWaitResult result = guestSession.WaitForArray(new GuestSessionWaitForFlag[] { GuestSessionWaitForFlag.GuestSessionWaitForFlag_Start }, 5000);

            if (result == GuestSessionWaitResult.GuestSessionWaitResult_Start)
            {
                // guest session ready
                IProgress copyProgress = guestSession.FileCopyToGuest(@"C:\path_to_host.file", @"C:\test.file", new FileCopyFlag[] { FileCopyFlag.FileCopyFlag_None });

                copyProgress.WaitForCompletion(5000);

                Console.WriteLine("Result: {0}", copyProgress.ResultCode);
            }

            guestSession.Close();

            session.UnlockMachine();
        }
    }


Running the code results in an error code of -2135228411 if no file or directory with the name "C:\test.file" exists in the guest.
If "C:\test.file" exists as a directory, then the file is copied into the guest successfully as "C:\test.file\test.file".
If "C:\test.file" exists as a file, it is successfully overwritten.
Magnus Madsen
 
Posts: 21
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: Issue with IGuestSession.CopyFileToGuest

Postby noteirak » 23. Nov 2017, 17:49

Have you tried writting to another directly rather than the root of the C: drive? Root of drives are typically not writable with a regular account (or with UAC enabled). When you create the folder under C:\, you would effectively create a regular folder. And I'm guessing you are creating the folder with the same account as the one you're using in the API calls.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Issue with IGuestSession.CopyFileToGuest

Postby Magnus Madsen » 23. Nov 2017, 19:18

Yeah, the root directory was just for the test, usually I write to a subdirectory where all users have access.

I don't think it is an rights issue, as I am able to write to files using the IGuestSession.FileOpen and the IGuestFile interface in the same path as CopyFileToGuest fails to write to.

The user account I am using is an administrator in the guest, and UAC is disabled as well.
Magnus Madsen
 
Posts: 21
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: Issue with IGuestSession.CopyFileToGuest

Postby noteirak » 23. Nov 2017, 19:19

Fair enough. I'll try to replicate this on my end before moving this to the dev-list
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Issue with IGuestSession.CopyFileToGuest

Postby Magnus Madsen » 2. May 2018, 09:55

I can confirm that VirtualBox 5.2.10 fixes this issue :)
Magnus Madsen
 
Posts: 21
Joined: 11. Jun 2013, 08:35
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: WinXP, WinVista, Win7, Win8

Re: Issue with IGuestSession.CopyFileToGuest

Postby socratis » 4. May 2018, 21:07

Great, thanks for the feedback. Marking as [Fixed].
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
socratis
Site Moderator
 
Posts: 25323
Joined: 22. Oct 2010, 11:03
Location: Greece
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 1 guest