Changeset 67239 in vbox
- Timestamp:
- Jun 2, 2017 1:37:59 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r67237 r67239 3068 3068 { 3069 3069 /* get source path and filename */ 3070 Utf8Str source MediumPath = i_getLocationFull();3071 Utf8Str source MediumFileName = i_getName();3070 Utf8Str sourcePath = i_getLocationFull(); 3071 Utf8Str sourceFName = i_getName(); 3072 3072 3073 3073 if (aLocation.isEmpty()) … … 3080 3080 3081 3081 /* extract destination path and filename */ 3082 Utf8Str dest MediumPath(aLocation);3083 Utf8Str dest MediumFileName(destMediumPath);3084 dest MediumFileName.stripPath();3085 3086 Utf8Str suffix(dest MediumFileName);3082 Utf8Str destPath(aLocation); 3083 Utf8Str destFName(destPath); 3084 destFName.stripPath(); 3085 3086 Utf8Str suffix(destFName); 3087 3087 suffix.stripSuffix(); 3088 3088 3089 if (suffix.equals(dest MediumFileName) && !destMediumFileName.isEmpty())3089 if (suffix.equals(destFName) && !destFName.isEmpty()) 3090 3090 { 3091 3091 /* 3092 * small trick. This case means target path has no filename at the end. 3093 * it will look like "/path/to/new/location" or just "newname" 3094 * there is no backslash in the end 3095 * or there is no filename with extension(suffix) in the end 3092 * The target path has no filename: Either "/path/to/new/location" or 3093 * just "newname" (no trailing backslash or there is no filename with 3094 * extension(suffix)). 3096 3095 */ 3097 3098 /* case when new path contains only "newname", no path, no extension */ 3099 if (destMediumPath.equals(destMediumFileName)) 3096 if (destPath.equals(destFName)) 3100 3097 { 3101 Utf8Str localSuffix = RTPathSuffix(sourceMediumFileName.c_str());3102 dest MediumFileName.append(localSuffix);3103 dest MediumPath = destMediumFileName;3098 /* new path contains only "newname", no path, no extension */ 3099 destFName.append(RTPathSuffix(sourceFName.c_str())); 3100 destPath = destFName; 3104 3101 } 3105 3102 else 3106 3103 { 3107 3104 /* new path looks like "/path/to/new/location" */ 3108 dest MediumFileName.setNull();3109 dest MediumPath.append(RTPATH_SLASH);3105 destFName.setNull(); 3106 destPath.append(RTPATH_SLASH); 3110 3107 } 3111 3108 } 3112 3109 3113 if (dest MediumFileName.isEmpty())3110 if (destFName.isEmpty()) 3114 3111 { 3115 3112 /* No target name */ 3116 dest MediumPath.append(sourceMediumFileName);3113 destPath.append(sourceFName); 3117 3114 } 3118 3115 else 3119 3116 { 3120 if (dest MediumPath.equals(destMediumFileName))3117 if (destPath.equals(destFName)) 3121 3118 { 3122 3119 /* 3123 * the passed target path consist of only a filename without directory 3124 * next move medium within the source directory with the passed new name 3120 * The target path contains of only a filename without a directory. 3121 * Move the medium within the source directory to the new name 3122 * (actually rename operation). 3123 * Scratches sourcePath! 3125 3124 */ 3126 dest MediumPath = sourceMediumPath.stripFilename().append(RTPATH_SLASH).append(destMediumFileName);3125 destPath = sourcePath.stripFilename().append(RTPATH_SLASH).append(destFName); 3127 3126 } 3128 3127 suffix = i_getFormat(); 3129 3130 3128 if (suffix.compare("RAW", Utf8Str::CaseInsensitive) == 0) 3131 3129 { … … 3140 3138 } 3141 3139 } 3142 /* set the target extension like on the source. Any conversions are prohibited */3140 /* Set the target extension like on the source. Any conversions are prohibited */ 3143 3141 suffix.toLower(); 3144 destMediumPath.stripSuffix().append('.').append(suffix); 3145 } 3146 3147 if (i_isMediumFormatFile()) 3148 { 3149 /* Path must be absolute */ 3150 char *pszAbs = RTPathAbsDup(destMediumPath.c_str()); 3151 int iCmp = destMediumPath.compare(pszAbs, Utf8Str::CaseInsensitive); 3152 RTStrFree(pszAbs); 3153 if (iCmp) 3154 { 3155 rc = setError(VBOX_E_FILE_ERROR, 3156 tr("The given target path '%s' is not absolute"), 3157 destMediumPath.c_str()); 3158 throw rc; 3159 } 3160 /* Check path for a new file object */ 3161 rc = VirtualBox::i_ensureFilePathExists(destMediumPath, true); 3162 if (FAILED(rc)) 3163 throw rc; 3164 } 3165 else 3142 destPath.stripSuffix().append('.').append(suffix); 3143 } 3144 3145 if (!i_isMediumFormatFile()) 3166 3146 { 3167 3147 rc = setError(VERR_NOT_A_FILE, 3168 tr("Medium '%s' isn't a file object. \"Move\" operation isn't supported."),3169 i_getLocationFull().c_str());3148 tr("Medium '%s' isn't a file object. \"Move\" operation isn't supported."), 3149 i_getLocationFull().c_str()); 3170 3150 throw rc; 3171 3151 } 3152 /* Path must be absolute */ 3153 if (!RTPathStartsWithRoot(destPath.c_str())) 3154 { 3155 rc = setError(VBOX_E_FILE_ERROR, 3156 tr("The given path '%s' is not fully qualified"), 3157 destPath.c_str()); 3158 throw rc; 3159 } 3160 /* Check path for a new file object */ 3161 rc = VirtualBox::i_ensureFilePathExists(destPath, true); 3162 if (FAILED(rc)) 3163 throw rc; 3172 3164 3173 3165 /* Set needed variables for "moving" procedure. It'll be used later in separate thread task */ 3174 rc = i_preparationForMoving(dest MediumPath);3166 rc = i_preparationForMoving(destPath); 3175 3167 if (FAILED(rc)) 3176 3168 { … … 3209 3201 { 3210 3202 rc = setError(VERR_VM_UNEXPECTED_VM_STATE, 3211 tr("At least VM '%s' to whom this medium '%s' attached has the opened session now. " 3212 "Stop all needed VM before set a new location."), 3203 tr("At least the VM '%s' to whom this medium '%s' attached has currently an opened session. Stop all VMs before relocating this medium"), 3213 3204 id.toString().c_str(), 3214 3205 i_getLocationFull().c_str()); … … 3279 3270 else 3280 3271 { 3281 if (pTask != NULL)3272 if (pTask) 3282 3273 delete pTask; 3283 3274 }
Note:
See TracChangeset
for help on using the changeset viewer.