From e6b7e1f6e1f580fdd8b68b981607b9b680e5e6c5 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Fri, 3 Nov 2017 18:26:08 +0100 Subject: [PATCH] vbox5: fix substring calculation for VM files in root directory Fixes #2561 --- repos/ports/ports/virtualbox5.hash | 2 +- repos/ports/src/virtualbox5/patches/series | 1 + .../src/virtualbox5/patches/substr.patch | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 repos/ports/src/virtualbox5/patches/substr.patch diff --git a/repos/ports/ports/virtualbox5.hash b/repos/ports/ports/virtualbox5.hash index d37952282..b17ce94ce 100644 --- a/repos/ports/ports/virtualbox5.hash +++ b/repos/ports/ports/virtualbox5.hash @@ -1 +1 @@ -c916354430e16892bbc739aaecd86b9451860326 +25d9be4a067a1c748bab7a60220d7477e552957a diff --git a/repos/ports/src/virtualbox5/patches/series b/repos/ports/src/virtualbox5/patches/series index 13337052a..2d36df281 100644 --- a/repos/ports/src/virtualbox5/patches/series +++ b/repos/ports/src/virtualbox5/patches/series @@ -9,3 +9,4 @@ dev_e1000.patch tm_tpr_vbox5.patch vm.patch mm.patch +substr.patch diff --git a/repos/ports/src/virtualbox5/patches/substr.patch b/repos/ports/src/virtualbox5/patches/substr.patch new file mode 100644 index 000000000..b45199079 --- /dev/null +++ b/repos/ports/src/virtualbox5/patches/substr.patch @@ -0,0 +1,39 @@ +substr.patch + +diff --git a/src/app/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp b/src/app/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp +index ef9811a..79ab5d6 100644 +--- a/src/app/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp ++++ b/src/app/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp +@@ -7347,7 +7347,11 @@ void Machine::i_copyPathRelativeToMachine(const Utf8Str &strSource, + if (RTPathStartsWith(strSource.c_str(), strTarget.c_str())) + { + // is relative: then append what's left +- strTarget = strSource.substr(strTarget.length() + 1); // skip '/' ++ if (RTPathIsSame(strTarget.c_str(), "/")) ++ strTarget = strSource.substr(strTarget.length()); // skip '/' ++ else ++ strTarget = strSource.substr(strTarget.length() + 1); // skip '/' ++ + // for empty paths (only possible for subdirs) use "." to avoid + // triggering default settings for not present config attributes. + if (strTarget.isEmpty()) +diff --git a/src/app/virtualbox/src/VBox/Main/src-server/MediumImpl.cpp b/src/app/virtualbox/src/VBox/Main/src-server/MediumImpl.cpp +index 9e83858..51d578f 100644 +--- a/src/app/virtualbox/src/VBox/Main/src-server/MediumImpl.cpp ++++ b/src/app/virtualbox/src/VBox/Main/src-server/MediumImpl.cpp +@@ -4507,9 +4507,12 @@ void Medium::i_saveSettingsOne(settings::Medium &data, const Utf8Str &strHardDis + // make path relative if needed + if ( !strHardDiskFolder.isEmpty() + && RTPathStartsWith(m->strLocationFull.c_str(), strHardDiskFolder.c_str()) +- ) +- data.strLocation = m->strLocationFull.substr(strHardDiskFolder.length() + 1); +- else ++ ) { ++ if (RTPathIsSame(strHardDiskFolder.c_str(), "/")) ++ data.strLocation = m->strLocationFull.substr(strHardDiskFolder.length()); ++ else ++ data.strLocation = m->strLocationFull.substr(strHardDiskFolder.length() + 1); ++ } else + data.strLocation = m->strLocationFull; + data.strFormat = m->strFormat; +