Changeset 72001 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 24, 2018 9:41:07 AM (7 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestSessionImpl.h
r71976 r72001 27 27 #include "GuestFileImpl.h" 28 28 #include "GuestFsObjInfoImpl.h" 29 #include "GuestSessionImplTasks.h" 29 30 30 31 #include <deque> … … 261 262 * @todo r=bird: Most of these are public for no real reason... 262 263 * @{ */ 264 HRESULT i_copyFromGuest(const GuestSessionFsSourceSet &SourceSet, const com::Utf8Str &strDestination, 265 ComPtr<IProgress> &pProgress); 266 HRESULT i_copyToGuest(const GuestSessionFsSourceSet &SourceSet, const com::Utf8Str &strDestination, 267 ComPtr<IProgress> &pProgress); 263 268 int i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc); 264 269 inline bool i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir); -
trunk/src/VBox/Main/include/GuestSessionImplTasks.h
r71979 r72001 35 35 class GuestSessionTaskInternalOpen; 36 36 37 /**38 * Enumeration which specifies the file system source type.39 */40 enum GuestSessionFsSourceType41 {42 /** Invalid / uknown source type, don't use. */43 GuestSessionFsSourceType_Unknown = 0,44 /** The source is a directory. */45 GuestSessionFsSourceType_Dir,46 /** The source is a file. */47 GuestSessionFsSourceType_File48 };49 37 50 38 /** … … 54 42 struct GuestSessionFsSourceSpec 55 43 { 56 Utf8Str 57 Utf8Str 58 GuestSessionFsSourceTypeenmType;59 PathStyle_T 60 bool 61 bool 44 Utf8Str strSource; 45 Utf8Str strFilter; 46 FsObjType_T enmType; 47 PathStyle_T enmPathStyle; 48 bool fDryRun; 49 bool fFollowSymlinks; 62 50 union 63 51 { -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r71977 r72001 722 722 LogFlowFuncLeaveRC(vrc); 723 723 return vrc; 724 } 725 726 /** 727 * Internal worker function for public APIs that handle copying elements from 728 * guest to the host. 729 * 730 * @return HRESULT 731 * @param SourceSet Source set specifying what to copy. 732 * @param strDestination Destination path on the host. Host path style. 733 * @param pProgress Progress object returned to the caller. 734 */ 735 HRESULT GuestSession::i_copyFromGuest(const GuestSessionFsSourceSet &SourceSet, 736 const com::Utf8Str &strDestination, ComPtr<IProgress> &pProgress) 737 { 738 HRESULT hrc = i_isReadyExternal(); 739 if (FAILED(hrc)) 740 return hrc; 741 742 LogFlowThisFuncEnter(); 743 744 /* Validate stuff. */ 745 if (RT_UNLIKELY(SourceSet.size() == 0 || *(SourceSet[0].strSource.c_str()) == '\0')) /* At least one source must be present. */ 746 return setError(E_INVALIDARG, tr("No source(s) specified")); 747 if (RT_UNLIKELY((strDestination.c_str()) == NULL || *(strDestination.c_str()) == '\0')) 748 return setError(E_INVALIDARG, tr("No destination specified")); 749 750 GuestSessionFsSourceSet::const_iterator itSource = SourceSet.begin(); 751 while (itSource != SourceSet.end()) 752 { 753 if (itSource->enmType == FsObjType_Directory) 754 { 755 if (itSource->Type.Dir.fCopyFlags) 756 { 757 if (!(itSource->Type.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting)) 758 return setError(E_INVALIDARG, tr("Invalid / not (yet) implemented directory copy flags specified")); 759 } 760 } 761 else if (itSource->enmType == FsObjType_File) 762 { 763 if (itSource->Type.File.fCopyFlags) 764 { 765 if ( !(itSource->Type.File.fCopyFlags & FileCopyFlag_NoReplace) 766 && !(itSource->Type.File.fCopyFlags & FileCopyFlag_FollowLinks) 767 && !(itSource->Type.File.fCopyFlags & FileCopyFlag_Update)) 768 { 769 return setError(E_NOTIMPL, tr("Invalid / not (yet) implemented file copy flag(s) specified")); 770 } 771 } 772 } 773 else 774 return setError(E_NOTIMPL, tr("Source type %RU32 not implemented"), itSource->enmType); 775 776 itSource++; 777 } 778 779 try 780 { 781 GuestSessionTaskCopyFrom *pTask = NULL; 782 ComObjPtr<Progress> pProgressObj; 783 try 784 { 785 pTask = new GuestSessionTaskCopyFrom(this /* GuestSession */, SourceSet, strDestination); 786 } 787 catch(...) 788 { 789 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyFrom object")); 790 throw; 791 } 792 793 hrc = pTask->Init(Utf8StrFmt(tr("Copying to \"%s\" on the host"), strDestination.c_str())); 794 if (FAILED(hrc)) 795 { 796 delete pTask; 797 hrc = setError(VBOX_E_IPRT_ERROR, 798 tr("Creating progress object for SessionTaskCopyFrom object failed")); 799 throw hrc; 800 } 801 802 hrc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 803 804 if (SUCCEEDED(hrc)) 805 { 806 /* Return progress to the caller. */ 807 pProgressObj = pTask->GetProgressObject(); 808 hrc = pProgressObj.queryInterfaceTo(pProgress.asOutParam()); 809 } 810 else 811 hrc = setError(VBOX_E_IPRT_ERROR, 812 tr("Starting thread for copying from guest to \"%s\" on the host failed"), strDestination.c_str()); 813 814 } 815 catch(std::bad_alloc &) 816 { 817 hrc = E_OUTOFMEMORY; 818 } 819 catch(HRESULT eHR) 820 { 821 hrc = eHR; 822 LogFlowThisFunc(("Exception was caught in the function\n")); 823 } 824 825 return hrc; 826 } 827 828 /** 829 * Internal worker function for public APIs that handle copying elements from 830 * host to the guest. 831 * 832 * @return HRESULT 833 * @param SourceSet Source set specifying what to copy. 834 * @param strDestination Destination path on the guest. Guest path style. 835 * @param pProgress Progress object returned to the caller. 836 */ 837 HRESULT GuestSession::i_copyToGuest(const GuestSessionFsSourceSet &SourceSet, 838 const com::Utf8Str &strDestination, ComPtr<IProgress> &pProgress) 839 { 840 HRESULT hrc = i_isReadyExternal(); 841 if (FAILED(hrc)) 842 return hrc; 843 844 LogFlowThisFuncEnter(); 845 846 /* Validate stuff. */ 847 if (RT_UNLIKELY(SourceSet.size() == 0 || *(SourceSet[0].strSource.c_str()) == '\0')) /* At least one source must be present. */ 848 return setError(E_INVALIDARG, tr("No source(s) specified")); 849 if (RT_UNLIKELY((strDestination.c_str()) == NULL || *(strDestination.c_str()) == '\0')) 850 return setError(E_INVALIDARG, tr("No destination specified")); 851 852 GuestSessionFsSourceSet::const_iterator itSource = SourceSet.begin(); 853 while (itSource != SourceSet.end()) 854 { 855 if (itSource->enmType == FsObjType_Directory) 856 { 857 if (itSource->Type.Dir.fCopyFlags) 858 { 859 if (!(itSource->Type.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting)) 860 return setError(E_INVALIDARG, tr("Invalid / not (yet) implemented directory copy flags specified")); 861 } 862 } 863 else if (itSource->enmType == FsObjType_File) 864 { 865 if (itSource->Type.File.fCopyFlags) 866 { 867 if ( !(itSource->Type.File.fCopyFlags & FileCopyFlag_NoReplace) 868 && !(itSource->Type.File.fCopyFlags & FileCopyFlag_FollowLinks) 869 && !(itSource->Type.File.fCopyFlags & FileCopyFlag_Update)) 870 { 871 return setError(E_NOTIMPL, tr("Invalid / not (yet) implemented file copy flag(s) specified")); 872 } 873 } 874 } 875 else 876 return setError(E_NOTIMPL, tr("Source type %RU32 not implemented"), itSource->enmType); 877 878 itSource++; 879 } 880 881 try 882 { 883 GuestSessionTaskCopyTo *pTask = NULL; 884 ComObjPtr<Progress> pProgressObj; 885 try 886 { 887 pTask = new GuestSessionTaskCopyTo(this /* GuestSession */, SourceSet, strDestination); 888 } 889 catch(...) 890 { 891 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyTo object")); 892 throw; 893 } 894 895 hrc = pTask->Init(Utf8StrFmt(tr("Copying to \"%s\" on the guest"), strDestination.c_str())); 896 if (FAILED(hrc)) 897 { 898 delete pTask; 899 hrc = setError(VBOX_E_IPRT_ERROR, 900 tr("Creating progress object for SessionTaskCopyTo object failed")); 901 throw hrc; 902 } 903 904 hrc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 905 906 if (SUCCEEDED(hrc)) 907 { 908 /* Return progress to the caller. */ 909 pProgress = pTask->GetProgressObject(); 910 hrc = pProgressObj.queryInterfaceTo(pProgress.asOutParam()); 911 } 912 else 913 hrc = setError(VBOX_E_IPRT_ERROR, 914 tr("Starting thread for copying from host to \"%s\" on the guest failed"), strDestination.c_str()); 915 916 } 917 catch(std::bad_alloc &) 918 { 919 hrc = E_OUTOFMEMORY; 920 } 921 catch(HRESULT eHR) 922 { 923 hrc = eHR; 924 LogFlowThisFunc(("Exception was caught in the function\n")); 925 } 926 927 return hrc; 724 928 } 725 929 … … 2595 2799 } 2596 2800 2597 HRESULT GuestSession::fileCopyFromGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDest ,2801 HRESULT GuestSession::fileCopyFromGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDestination, 2598 2802 const std::vector<FileCopyFlag_T> &aFlags, 2599 2803 ComPtr<IProgress> &aProgress) … … 2602 2806 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2603 2807 2604 if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))2605 return setError(E_INVALIDARG, tr("No source specified"));2606 if (RT_UNLIKELY((aDest.c_str()) == NULL || *(aDest.c_str()) == '\0'))2607 return setError(E_INVALIDARG, tr("No destination specified"));2608 2609 2808 uint32_t fFlags = FileCopyFlag_None; 2610 2809 if (aFlags.size()) … … 2614 2813 } 2615 2814 2616 if (fFlags) 2617 { 2618 if ( !(fFlags & FileCopyFlag_NoReplace) 2619 && !(fFlags & FileCopyFlag_FollowLinks) 2620 && !(fFlags & FileCopyFlag_Update)) 2621 { 2622 return setError(E_NOTIMPL, tr("Invalid / not (yet) implemented flag(s) specified")); 2623 } 2624 } 2625 2626 HRESULT hrc = i_isReadyExternal(); 2627 if (FAILED(hrc)) 2628 return hrc; 2629 2630 LogFlowThisFuncEnter(); 2631 2632 try 2633 { 2634 GuestSessionTaskCopyFrom *pTask = NULL; 2635 ComObjPtr<Progress> pProgress; 2636 try 2637 { 2638 GuestSessionFsSourceSpec source; 2639 source.strSource = aSource; 2640 source.enmType = GuestSessionFsSourceType_File; 2641 source.enmPathStyle = i_getPathStyle(); 2642 source.Type.File.fCopyFlags = (FileCopyFlag_T)fFlags; 2643 2644 GuestSessionFsSourceSet vecSources; 2645 vecSources.push_back(source); 2646 2647 pTask = new GuestSessionTaskCopyFrom(this /* GuestSession */, vecSources, aDest); 2648 } 2649 catch(...) 2650 { 2651 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyFrom object")); 2652 throw; 2653 } 2654 2655 2656 hrc = pTask->Init(Utf8StrFmt(tr("Copying \"%s\" from guest to \"%s\" on the host"), aSource.c_str(), aDest.c_str())); 2657 if (FAILED(hrc)) 2658 { 2659 delete pTask; 2660 hrc = setError(VBOX_E_IPRT_ERROR, 2661 tr("Creating progress object for SessionTaskCopyFrom object failed")); 2662 throw hrc; 2663 } 2664 2665 hrc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 2666 2667 if (SUCCEEDED(hrc)) 2668 { 2669 /* Return progress to the caller. */ 2670 pProgress = pTask->GetProgressObject(); 2671 hrc = pProgress.queryInterfaceTo(aProgress.asOutParam()); 2672 } 2673 else 2674 hrc = setError(VBOX_E_IPRT_ERROR, 2675 tr("Starting thread for copying file \"%s\" from guest to \"%s\" on the host failed "), 2676 aSource.c_str(), aDest.c_str()); 2677 2678 } 2679 catch(std::bad_alloc &) 2680 { 2681 hrc = E_OUTOFMEMORY; 2682 } 2683 catch(HRESULT eHR) 2684 { 2685 hrc = eHR; 2686 LogFlowThisFunc(("Exception was caught in the function \n")); 2687 } 2688 2689 return hrc; 2690 } 2691 2692 HRESULT GuestSession::fileCopyToGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDest, 2815 GuestSessionFsSourceSet SourceSet; 2816 2817 GuestSessionFsSourceSpec source; 2818 source.strSource = aSource; 2819 source.enmType = FsObjType_File; 2820 source.enmPathStyle = i_getPathStyle(); 2821 source.Type.File.fCopyFlags = (FileCopyFlag_T)fFlags; 2822 2823 SourceSet.push_back(source); 2824 2825 return i_copyFromGuest(SourceSet, aDestination, aProgress); 2826 } 2827 2828 HRESULT GuestSession::fileCopyToGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDestination, 2693 2829 const std::vector<FileCopyFlag_T> &aFlags, ComPtr<IProgress> &aProgress) 2694 2830 { … … 2696 2832 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2697 2833 2698 if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))2699 return setError(E_INVALIDARG, tr("No source specified"));2700 if (RT_UNLIKELY((aDest.c_str()) == NULL || *(aDest.c_str()) == '\0'))2701 return setError(E_INVALIDARG, tr("No destination specified"));2702 2703 2834 uint32_t fFlags = FileCopyFlag_None; 2704 2835 if (aFlags.size()) … … 2708 2839 } 2709 2840 2710 if (fFlags) 2711 { 2712 if ( !(fFlags & FileCopyFlag_NoReplace) 2713 && !(fFlags & FileCopyFlag_FollowLinks) 2714 && !(fFlags & FileCopyFlag_Update)) 2715 { 2716 return setError(E_NOTIMPL, tr("Invalid / not (yet) implemented flag(s) specified")); 2717 } 2718 } 2719 2720 HRESULT hrc = i_isReadyExternal(); 2721 if (FAILED(hrc)) 2722 return hrc; 2723 2724 LogFlowThisFuncEnter(); 2725 2726 try 2727 { 2728 GuestSessionTaskCopyTo *pTask = NULL; 2729 ComObjPtr<Progress> pProgress; 2730 try 2731 { 2732 GuestSessionFsSourceSpec source; 2733 source.strSource = aSource; 2734 source.enmType = GuestSessionFsSourceType_File; 2735 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 2736 source.enmPathStyle = PathStyle_DOS; 2737 #else 2738 source.enmPathStyle = PathStyle_UNIX; 2739 #endif 2740 source.Type.File.fCopyFlags = (FileCopyFlag_T)fFlags; 2741 2742 GuestSessionFsSourceSet vecSources; 2743 vecSources.push_back(source); 2744 2745 pTask = new GuestSessionTaskCopyTo(this /* GuestSession */, vecSources, aDest); 2746 } 2747 catch(...) 2748 { 2749 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyTo object")); 2750 throw; 2751 } 2752 2753 hrc = pTask->Init(Utf8StrFmt(tr("Copying \"%s\" from host to \"%s\" on the guest"), aSource.c_str(), aDest.c_str())); 2754 if (FAILED(hrc)) 2755 { 2756 delete pTask; 2757 hrc = setError(VBOX_E_IPRT_ERROR, 2758 tr("Creating progress object for SessionTaskCopyTo object failed")); 2759 throw hrc; 2760 } 2761 2762 hrc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 2763 2764 if (SUCCEEDED(hrc)) 2765 { 2766 /* Return progress to the caller. */ 2767 pProgress = pTask->GetProgressObject(); 2768 hrc = pProgress.queryInterfaceTo(aProgress.asOutParam()); 2769 } 2770 else 2771 hrc = setError(VBOX_E_IPRT_ERROR, 2772 tr("Starting thread for copying file \"%s\" from host to \"%s\" on the guest failed "), 2773 aSource.c_str(), aDest.c_str()); 2774 } 2775 catch(std::bad_alloc &) 2776 { 2777 hrc = E_OUTOFMEMORY; 2778 } 2779 catch(HRESULT eHR) 2780 { 2781 hrc = eHR; 2782 LogFlowThisFunc(("Exception was caught in the function \n")); 2783 } 2784 2785 return hrc; 2841 GuestSessionFsSourceSet SourceSet; 2842 2843 GuestSessionFsSourceSpec source; 2844 source.strSource = aSource; 2845 source.enmType = FsObjType_File; 2846 source.enmPathStyle = i_getPathStyle(); 2847 source.Type.File.fCopyFlags = (FileCopyFlag_T)fFlags; 2848 2849 SourceSet.push_back(source); 2850 2851 return i_copyToGuest(SourceSet, aDestination, aProgress); 2786 2852 } 2787 2853 … … 2790 2856 const com::Utf8Str &aDestination, ComPtr<IProgress> &aProgress) 2791 2857 { 2792 RT_NOREF(aSources, aFilters, aTypes, aFlags, aDestination, aProgress); 2793 ReturnComNotImplemented(); 2858 AutoCaller autoCaller(this); 2859 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2860 2861 const size_t cSources = aSources.size(); 2862 if ( aFilters.size() != cSources 2863 || aTypes.size() != cSources 2864 || aFlags.size() != cSources) 2865 { 2866 return setError(E_INVALIDARG, tr("Parameter array sizes don't match to the number of sources specified")); 2867 } 2868 2869 GuestSessionFsSourceSet SourceSet; 2870 2871 std::vector<com::Utf8Str>::const_iterator itSource = aSources.begin(); 2872 std::vector<com::Utf8Str>::const_iterator itFilter = aFilters.begin(); 2873 std::vector<FsObjType_T>::const_iterator itType = aTypes.begin(); 2874 std::vector<GuestCopyFlag_T>::const_iterator itFlag = aFlags.begin(); 2875 2876 while (itSource != aSources.end()) 2877 { 2878 GuestSessionFsSourceSpec source; 2879 source.strSource = *itSource; 2880 source.strFilter = *itFilter; 2881 source.enmType = *itType; 2882 source.enmPathStyle = i_getPathStyle(); 2883 2884 if (*itType == FsObjType_Directory) 2885 { 2886 source.Type.Dir.fCopyFlags = (DirectoryCopyFlag_T)*itFlag; 2887 source.Type.Dir.fRecursive = true; /* Implicit. */ 2888 } 2889 else 2890 { 2891 source.Type.File.fCopyFlags = (FileCopyFlag_T)*itFlag; 2892 } 2893 2894 SourceSet.push_back(source); 2895 2896 ++itSource; 2897 ++itFilter; 2898 ++itType; 2899 ++itFlag; 2900 } 2901 2902 return i_copyFromGuest(SourceSet, aDestination, aProgress); 2794 2903 } 2795 2904 … … 2798 2907 const com::Utf8Str &aDestination, ComPtr<IProgress> &aProgress) 2799 2908 { 2800 RT_NOREF(aSources, aFilters, aTypes, aFlags, aDestination, aProgress); 2801 ReturnComNotImplemented(); 2909 AutoCaller autoCaller(this); 2910 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2911 2912 const size_t cSources = aSources.size(); 2913 if ( aFilters.size() != cSources 2914 || aTypes.size() != cSources 2915 || aFlags.size() != cSources) 2916 { 2917 return setError(E_INVALIDARG, tr("Parameter array sizes don't match to the number of sources specified")); 2918 } 2919 2920 GuestSessionFsSourceSet SourceSet; 2921 2922 std::vector<com::Utf8Str>::const_iterator itSource = aSources.begin(); 2923 std::vector<com::Utf8Str>::const_iterator itFilter = aFilters.begin(); 2924 std::vector<FsObjType_T>::const_iterator itType = aTypes.begin(); 2925 std::vector<GuestCopyFlag_T>::const_iterator itFlag = aFlags.begin(); 2926 2927 while (itSource != aSources.end()) 2928 { 2929 2930 GuestSessionFsSourceSpec source; 2931 source.strSource = *itSource; 2932 source.strFilter = *itFilter; 2933 source.enmType = *itType; 2934 source.enmPathStyle = i_getPathStyle(); 2935 2936 if (*itType == FsObjType_Directory) 2937 { 2938 source.Type.Dir.fCopyFlags = (DirectoryCopyFlag_T)*itFlag; 2939 source.Type.Dir.fRecursive = true; /* Implicit. */ 2940 } 2941 else 2942 source.Type.File.fCopyFlags = (FileCopyFlag_T)*itFlag; 2943 2944 SourceSet.push_back(source); 2945 2946 ++itSource; 2947 ++itFilter; 2948 ++itType; 2949 ++itFlag; 2950 } 2951 2952 return i_copyToGuest(SourceSet, aDestination, aProgress); 2802 2953 } 2803 2954 … … 2815 2966 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2816 2967 2817 if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))2818 return setError(E_INVALIDARG, tr("No source directory specified"));2819 2820 if (RT_UNLIKELY((aDestination.c_str()) == NULL || *(aDestination.c_str()) == '\0'))2821 return setError(E_INVALIDARG, tr("No destination directory specified"));2822 2823 2968 uint32_t fFlags = DirectoryCopyFlag_None; 2824 2969 if (aFlags.size()) … … 2828 2973 } 2829 2974 2830 if (fFlags) 2831 { 2832 if (!(fFlags & DirectoryCopyFlag_CopyIntoExisting)) 2833 return setError(E_INVALIDARG, tr("Invalid flags specified")); 2834 } 2835 2836 HRESULT hrc = i_isReadyExternal(); 2837 if (FAILED(hrc)) 2838 return hrc; 2839 2840 LogFlowThisFuncEnter(); 2841 2842 try 2843 { 2844 GuestSessionTaskCopyFrom *pTask = NULL; 2845 ComObjPtr<Progress> pProgress; 2846 try 2847 { 2848 GuestSessionFsSourceSpec source; 2849 source.strSource = aSource; 2850 source.enmType = GuestSessionFsSourceType_Dir; 2851 source.enmPathStyle = i_getPathStyle(); 2852 source.Type.Dir.fCopyFlags = (DirectoryCopyFlag_T)fFlags; 2853 2854 GuestSessionFsSourceSet vecSources; 2855 vecSources.push_back(source); 2856 2857 pTask = new GuestSessionTaskCopyFrom(this /* GuestSession */, vecSources, aDestination); 2858 } 2859 catch(...) 2860 { 2861 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyFrom object")); 2862 throw; 2863 } 2864 2865 hrc = pTask->Init(Utf8StrFmt(tr("Copying directory \"%s\" from guest to \"%s\" on the host"), 2866 aSource.c_str(), aDestination.c_str())); 2867 if (FAILED(hrc)) 2868 { 2869 delete pTask; 2870 hrc = setError(VBOX_E_IPRT_ERROR, 2871 tr("Creating progress object for SessionTaskCopyDirFrom object failed")); 2872 throw hrc; 2873 } 2874 2875 hrc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 2876 2877 if (SUCCEEDED(hrc)) 2878 { 2879 /* Return progress to the caller. */ 2880 pProgress = pTask->GetProgressObject(); 2881 hrc = pProgress.queryInterfaceTo(aProgress.asOutParam()); 2882 } 2883 else 2884 hrc = setError(VBOX_E_IPRT_ERROR, 2885 tr("Starting thread for copying directory \"%s\" from guest to \"%s\" on the host failed"), 2886 aSource.c_str(), aDestination.c_str()); 2887 } 2888 catch(std::bad_alloc &) 2889 { 2890 hrc = E_OUTOFMEMORY; 2891 } 2892 catch(HRESULT eHR) 2893 { 2894 hrc = eHR; 2895 LogFlowThisFunc(("Exception was caught in the function\n")); 2896 } 2897 2898 return hrc; 2975 GuestSessionFsSourceSet SourceSet; 2976 2977 GuestSessionFsSourceSpec source; 2978 source.strSource = aSource; 2979 source.enmType = FsObjType_Directory; 2980 source.enmPathStyle = i_getPathStyle(); 2981 source.Type.Dir.fCopyFlags = (DirectoryCopyFlag_T)fFlags; 2982 source.Type.Dir.fRecursive = true; /* Implicit. */ 2983 2984 SourceSet.push_back(source); 2985 2986 return i_copyFromGuest(SourceSet, aDestination, aProgress); 2899 2987 } 2900 2988 … … 2905 2993 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2906 2994 2907 if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))2908 return setError(E_INVALIDARG, tr("No source directory specified"));2909 2910 if (RT_UNLIKELY((aDestination.c_str()) == NULL || *(aDestination.c_str()) == '\0'))2911 return setError(E_INVALIDARG, tr("No destination directory specified"));2912 2913 if (!RTPathExists(aSource.c_str()))2914 return setError(E_INVALIDARG, tr("Source directory \"%s\" does not exist"), aSource.c_str());2915 2916 2995 uint32_t fFlags = DirectoryCopyFlag_None; 2917 2996 if (aFlags.size()) … … 2921 3000 } 2922 3001 2923 if (fFlags) 2924 { 2925 if (!(fFlags & DirectoryCopyFlag_CopyIntoExisting)) 2926 return setError(E_INVALIDARG, tr("Invalid flags specified")); 2927 } 2928 2929 HRESULT hrc = i_isReadyExternal(); 2930 if (FAILED(hrc)) 2931 return hrc; 2932 2933 LogFlowThisFuncEnter(); 2934 2935 try 2936 { 2937 GuestSessionTaskCopyTo *pTask = NULL; 2938 ComObjPtr<Progress> pProgress; 2939 try 2940 { 2941 GuestSessionFsSourceSpec source; 2942 source.strSource = aSource; 2943 source.enmType = GuestSessionFsSourceType_Dir; 2944 #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS 2945 source.enmPathStyle = PathStyle_DOS; 2946 #else 2947 source.enmPathStyle = PathStyle_UNIX; 2948 #endif 2949 source.fFollowSymlinks = true; 2950 source.Type.Dir.fRecursive = true; 2951 source.Type.Dir.fCopyFlags = (DirectoryCopyFlag_T)fFlags; 2952 2953 GuestSessionFsSourceSet vecSources; 2954 vecSources.push_back(source); 2955 2956 pTask = new GuestSessionTaskCopyTo(this /* GuestSession */, vecSources, aDestination); 2957 } 2958 catch(...) 2959 { 2960 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyTo object")); 2961 throw; 2962 } 2963 2964 hrc = pTask->Init(Utf8StrFmt(tr("Copying directory \"%s\" from host to \"%s\" on the guest"), 2965 aSource.c_str(), aDestination.c_str())); 2966 if (FAILED(hrc)) 2967 { 2968 delete pTask; 2969 hrc = setError(VBOX_E_IPRT_ERROR, 2970 tr("Creating progress object for SessionTaskCopyDirTo object failed")); 2971 throw hrc; 2972 } 2973 2974 hrc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER); 2975 2976 if (SUCCEEDED(hrc)) 2977 { 2978 /* Return progress to the caller. */ 2979 pProgress = pTask->GetProgressObject(); 2980 hrc = pProgress.queryInterfaceTo(aProgress.asOutParam()); 2981 } 2982 else 2983 hrc = setError(VBOX_E_IPRT_ERROR, 2984 tr("Starting thread for copying directory \"%s\" from host to \"%s\" on the guest failed"), 2985 aSource.c_str(), aDestination.c_str()); 2986 } 2987 catch(std::bad_alloc &) 2988 { 2989 hrc = E_OUTOFMEMORY; 2990 } 2991 catch(HRESULT eHR) 2992 { 2993 hrc = eHR; 2994 LogFlowThisFunc(("Exception was caught in the function\n")); 2995 } 2996 2997 return hrc; 3002 GuestSessionFsSourceSet SourceSet; 3003 3004 GuestSessionFsSourceSpec source; 3005 source.strSource = aSource; 3006 source.enmType = FsObjType_Directory; 3007 source.enmPathStyle = i_getPathStyle(); 3008 source.Type.Dir.fCopyFlags = (DirectoryCopyFlag_T)fFlags; 3009 source.Type.Dir.fRecursive = true; /* Implicit. */ 3010 3011 SourceSet.push_back(source); 3012 3013 return i_copyToGuest(SourceSet, aDestination, aProgress); 2998 3014 } 2999 3015 -
trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
r71976 r72001 981 981 982 982 /* If the source is a directory, make sure the path is properly terminated already. */ 983 if (mSourceSpec.enmType == GuestSessionFsSourceType_Dir)983 if (mSourceSpec.enmType == FsObjType_Directory) 984 984 { 985 985 if ( !mSrcRootAbs.endsWith("/") … … 1529 1529 Utf8Str strDst = mDest; 1530 1530 1531 if (itSrc->enmType == GuestSessionFsSourceType_Dir)1531 if (itSrc->enmType == FsObjType_Directory) 1532 1532 { 1533 1533 /* If the source does not end with a slash, copy over the entire directory … … 1554 1554 if (srcObjData.mType == FsObjType_Directory) 1555 1555 { 1556 if (itSrc->enmType != GuestSessionFsSourceType_Dir)1556 if (itSrc->enmType != FsObjType_Directory) 1557 1557 { 1558 1558 rc = VERR_NOT_A_FILE; … … 1562 1562 else 1563 1563 { 1564 if (itSrc->enmType != GuestSessionFsSourceType_File)1564 if (itSrc->enmType != FsObjType_File) 1565 1565 { 1566 1566 rc = VERR_NOT_A_DIRECTORY; … … 1572 1572 1573 1573 #if 0 1574 if (itSrc->enmType == GuestSessionFsSourceType_Dir)1574 if (itSrc->enmType == FsObjType_Directory) 1575 1575 { 1576 1576 bool fDstExists = RTDirExists(strDstDir.c_str()); … … 1621 1621 } 1622 1622 } 1623 else if (itSrc->enmType == GuestSessionFsSourceType_File)1623 else if (itSrc->enmType == FsObjType_File) 1624 1624 { 1625 1625 … … 1636 1636 if (RT_SUCCESS(rc)) 1637 1637 { 1638 if (itSrc->enmType == GuestSessionFsSourceType_Dir)1638 if (itSrc->enmType == FsObjType_Directory) 1639 1639 { 1640 1640 rc = pFsList->AddDirFromGuest(strSrc); … … 1704 1704 1705 1705 /* Create the root directory. */ 1706 if (pList->mSourceSpec.enmType == GuestSessionFsSourceType_Dir)1706 if (pList->mSourceSpec.enmType == FsObjType_Directory) 1707 1707 { 1708 1708 rc = RTDirCreate(pList->mDstRootAbs.c_str(), fDirMode, 0 /* fCreate */); … … 1722 1722 Utf8Str strSrcAbs = pList->mSrcRootAbs; 1723 1723 Utf8Str strDstAbs = pList->mDstRootAbs; 1724 if (pList->mSourceSpec.enmType == GuestSessionFsSourceType_Dir)1724 if (pList->mSourceSpec.enmType == FsObjType_Directory) 1725 1725 { 1726 1726 strSrcAbs += pEntry->strPath; … … 1820 1820 Utf8Str strDst = mDest; 1821 1821 1822 if (itSrc->enmType == GuestSessionFsSourceType_Dir)1822 if (itSrc->enmType == FsObjType_Directory) 1823 1823 { 1824 1824 /* If the source does not end with a slash, copy over the entire directory … … 1842 1842 if (RTFS_IS_DIRECTORY(srcFsObjInfo.Attr.fMode)) 1843 1843 { 1844 if (itSrc->enmType != GuestSessionFsSourceType_Dir)1844 if (itSrc->enmType != FsObjType_Directory) 1845 1845 { 1846 1846 rc = VERR_NOT_A_FILE; … … 1850 1850 else 1851 1851 { 1852 if (itSrc->enmType == GuestSessionFsSourceType_Dir)1852 if (itSrc->enmType == FsObjType_Directory) 1853 1853 { 1854 1854 rc = VERR_NOT_A_DIRECTORY; … … 1866 1866 if (RT_SUCCESS(rc)) 1867 1867 { 1868 if (itSrc->enmType == GuestSessionFsSourceType_Dir)1868 if (itSrc->enmType == FsObjType_Directory) 1869 1869 { 1870 1870 rc = pFsList->AddDirFromHost(strSrc); … … 1933 1933 1934 1934 /* Create the root directory. */ 1935 if (pList->mSourceSpec.enmType == GuestSessionFsSourceType_Dir)1935 if (pList->mSourceSpec.enmType == FsObjType_Directory) 1936 1936 { 1937 1937 rc = directoryCreate(pList->mDstRootAbs.c_str(), DirectoryCreateFlag_None, fDirMode, fFollowSymlinks); … … 1951 1951 Utf8Str strSrcAbs = pList->mSrcRootAbs; 1952 1952 Utf8Str strDstAbs = pList->mDstRootAbs; 1953 if (pList->mSourceSpec.enmType == GuestSessionFsSourceType_Dir)1953 if (pList->mSourceSpec.enmType == FsObjType_Directory) 1954 1954 { 1955 1955 strSrcAbs += pEntry->strPath;
Note:
See TracChangeset
for help on using the changeset viewer.