Skip to content

Commit 94a0cd9

Browse files
fix: SG-42147: Fix rvpkg -remove <package_name> (#1370)
### fix: [SG-42147](https://autodesk.atlassian.net/browse/SG-42147): Fix rvpkg -remove <package_name> ### Summarize your change. - [X] Add `baseNameFromPackageFileName()` helper function to avoid duplicating regex matching that was already present in `loadPackageInfo()` - [X] Replace all `cd()` calls with `filePath()` to make sure the path is formed the expected way instead of failing silently - [X] Remove unnecessary `pfile` variable that was unused in `uninstallPackage()` - [X] Remove unnecessary supportdir/<package_name> directory creation just to delete it after and only call `removeRecursively()` if that directory exists - [X] Set `m_packages[i].file` and `m_packages[i].baseName` respectively to the missing package path and name to make sure both values exist before using them in `uninstallPackage()` - [X] Validate that the incoming package to remove actually exists in `removePackages()` to prevent logging an error about it not being removed if it was already manually removed ### Describe the reason for the change. When calling `rvpkg -remove <package_name>` after manually deleting the .rvpkg for that package, the whole parent directory of the one you were currently in would get recursively removed. Since the file did not exist, the bare file name from rvinstall was kept instead of its absolute path causing `uninstallPackage()` to resolved against the current working directory. Every `cd()` into the sub-directories were silently failing since nothing was checking the return value of the call, so `supportdir` was left pointing at the parent of the current working directory (because of `rdir.cdUp()`) when `removeRecursively()` was called on it. Some other QDir errors were also shown because the package base name would resolved to an empty string which is not a valid directory. ### Describe what you have tested and on which operating system. Calling `rvpkg -remove <package_name>` after manually deleting the .rvpkg for that package was tested on Rocky Linux 9. Signed-off-by: Éloïse Brosseau <eloise.brosseau@autodesk.com>
1 parent 6a3af6e commit 94a0cd9

1 file changed

Lines changed: 32 additions & 40 deletions

File tree

src/lib/app/RvPackage/PackageManager.cpp

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020

2121
#include <QRegularExpression>
2222

23+
namespace
24+
{
25+
QString baseNameFromPackageFileName(const QString& fileName)
26+
{
27+
QRegularExpressionMatch match = QRegularExpression(R"((.*)-[0-9]+\.[0-9]+\.rvpkg)").match(fileName);
28+
29+
if (!match.hasMatch())
30+
{
31+
match = QRegularExpression(R"((.*)\.zip)").match(fileName);
32+
}
33+
34+
return match.hasMatch() ? match.captured(1) : QString();
35+
}
36+
} // namespace
37+
2338
namespace Rv
2439
{
2540
using namespace std;
@@ -812,30 +827,17 @@ namespace Rv
812827
QFileInfo info(package.file);
813828
QDir rdir = info.absoluteDir();
814829
rdir.cdUp();
815-
QDir mudir = rdir;
816-
QDir pydir = rdir;
817-
QDir supportdir = rdir;
818-
QDir imgdir = rdir;
819-
QDir movdir = rdir;
820-
QDir libdir = rdir;
821-
QDir nodedir = rdir;
822-
QDir profdir = rdir;
823830

824-
mudir.cd("Mu");
825-
pydir.cd("Python");
826-
supportdir.cd("SupportFiles");
827-
imgdir.cd("ImageFormats");
828-
movdir.cd("MovieFormats");
829-
libdir.cd("lib");
830-
nodedir.cd("Nodes");
831-
profdir.cd("Nodes");
831+
const QString pname = package.baseName;
832832

833-
QFileInfo pfile(package.file);
834-
QString pname = package.baseName;
835-
836-
if (!supportdir.exists(pname))
837-
supportdir.mkdir(pname);
838-
supportdir.cd(pname);
833+
QDir mudir(rdir.filePath("Mu"));
834+
QDir pydir(rdir.filePath("Python"));
835+
QDir supportdir(rdir.filePath("SupportFiles/" + pname));
836+
QDir imgdir(rdir.filePath("ImageFormats"));
837+
QDir movdir(rdir.filePath("MovieFormats"));
838+
QDir libdir(rdir.filePath("lib"));
839+
QDir nodedir(rdir.filePath("Nodes"));
840+
QDir profdir(rdir.filePath("Profiles"));
839841

840842
// Skip dependency check if requested
841843
if (!m_skipDependencyCheck)
@@ -988,8 +990,10 @@ namespace Rv
988990
// Remove the dangling supportdir
989991
//
990992

991-
if (!supportdir.removeRecursively())
993+
if (!pname.isEmpty() && supportdir.exists() && !supportdir.removeRecursively())
994+
{
992995
notremoved.push_back(supportdir.absolutePath());
996+
}
993997

994998
//
995999
// Report what was unremovable
@@ -1351,20 +1355,7 @@ namespace Rv
13511355
});
13521356
}
13531357

1354-
QRegularExpression rvpkgRE(R"((.*)-[0-9]+\.[0-9]+\.rvpkg)");
1355-
QRegularExpression zipRE(R"((.*)\.zip)");
1356-
1357-
QRegularExpressionMatch match = rvpkgRE.match(finfo.fileName());
1358-
if (!match.hasMatch())
1359-
{
1360-
match = zipRE.match(finfo.fileName());
1361-
}
1362-
if (match.hasMatch())
1363-
{
1364-
pname = match.captured(1);
1365-
}
1366-
1367-
package.baseName = pname;
1358+
package.baseName = baseNameFromPackageFileName(finfo.fileName());
13681359
}
13691360
}
13701361
}
@@ -1506,13 +1497,14 @@ namespace Rv
15061497
if (i == m_packageMap.end())
15071498
{
15081499
m_packages.push_back(Package());
1509-
m_packages.back().file = line;
1500+
m_packages.back().file = path;
1501+
m_packages.back().baseName = baseNameFromPackageFileName(QFileInfo(path).fileName());
15101502
m_packages.back().installed = installed;
15111503
m_packages.back().zipFile = false;
15121504
m_packages.back().name = "Missing Package";
15131505
m_packages.back().description = "<p><i>The original zip file for this package is "
15141506
"missing</i></p>";
1515-
m_packageMap.insert(line, m_packages.size() - 1);
1507+
m_packageMap.insert(path, m_packages.size() - 1);
15161508
}
15171509
else
15181510
{
@@ -1863,7 +1855,7 @@ namespace Rv
18631855

18641856
m_packages.erase(m_packages.begin() + q);
18651857

1866-
if (!QFile::remove(files[i]))
1858+
if (incomingFI.exists() && !QFile::remove(files[i]))
18671859
{
18681860
cerr << "ERROR: " << files[i].toUtf8().constData() << " not removed" << endl;
18691861
}

0 commit comments

Comments
 (0)