Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] BUG: Fix temporary folder containing special characters #7460

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion Base/Python/slicer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,10 @@ def tempDirectory(key="__SlicerTemp__", tempDir=None, includeDateTime=True):
if not tempDir:
tempDir = qt.QDir(slicer.app.temporaryPath)
if includeDateTime:
tempDirName = key + qt.QDateTime().currentDateTime().toString("yyyy-MM-dd_hh+mm+ss.zzz")
# Force using en-US locale, otherwise for example on a computer with
# Egyptian Arabic (ar-EG) locale, Arabic numerals may be used.
enUsLocale = qt.QLocale(qt.QLocale.English, qt.QLocale.UnitedStates)
tempDirName = key + enUsLocale.toString(qt.QDateTime.currentDateTime(), "yyyy-MM-dd_hh+mm+ss.zzz")
else:
tempDirName = key
fileInfo = qt.QFileInfo(qt.QDir(tempDir), tempDirName)
Expand Down
10 changes: 8 additions & 2 deletions Base/QTGUI/qSlicerApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,15 @@ void qSlicerApplication::setupFileLogging()

// Add new log file path for the current session
QString tempDir = this->temporaryPath();
// Force using en-US locale, otherwise for example on a computer with
// Egyptian Arabic (ar-EG) locale, Arabic numerals may be used.
QLocale enUsLocale = QLocale(QLocale::English, QLocale::UnitedStates);
QString currentLogFilePath = QString("%1/%2_%3_%4_%5_%6.log")
.arg(tempDir)
.arg(this->applicationName())
.arg(qSlicerApplication::application()->applicationVersion())
.arg(qSlicerApplication::application()->mainApplicationRevision())
.arg(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"))
.arg(enUsLocale.toString(QDateTime::currentDateTime(), "yyyyMMdd_hhmmss"))
.arg(QRandomGenerator::global()->generate() % 1000, 3, 10, QLatin1Char('0'));
logFilePaths.prepend(currentLogFilePath);

Expand Down Expand Up @@ -1117,9 +1120,12 @@ void qSlicerApplication::logApplicationInformation() const

int titleIndex = 0;
// Session start time
// Force using en-US locale, otherwise for example on a computer with
// Egyptian Arabic (ar-EG) locale, Arabic numerals may be used.
QLocale enUsLocale = QLocale(QLocale::English, QLocale::UnitedStates);
qDebug("%s: %s",
qPrintable(titles.at(titleIndex++).leftJustified(titleWidth, '.')),
qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")));
qPrintable(enUsLocale.toString(QDateTime::currentDateTime(), "yyyyMMdd_hhmmss")));

// Slicer version
qDebug("%s: %s (revision %s / %s) %s - %s %s",
Expand Down
5 changes: 4 additions & 1 deletion Modules/Scripted/DICOMLib/DICOMUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ def importFromDICOMWeb(
outputDirectoryBase = slicer.dicomDatabase.databaseDirectory + "/DICOMweb"
if not os.access(outputDirectoryBase, os.F_OK):
os.makedirs(outputDirectoryBase)
outputDirectoryBase += "/" + qt.QDateTime.currentDateTime().toString("yyyyMMdd-hhmmss")
# Force using en-US locale, otherwise for example on a computer with
# Egyptian Arabic (ar-EG) locale, Arabic numerals may be used.
enUsLocale = qt.QLocale(qt.QLocale.English, qt.QLocale.UnitedStates)
outputDirectoryBase += "/" + enUsLocale.toString(qt.QDateTime.currentDateTime(), "yyyyMMdd-hhmmss")
outputDirectory = qt.QTemporaryDir(outputDirectoryBase) # Add unique substring to directory
outputDirectory.setAutoRemove(False)
outputDirectoryPath = outputDirectory.path()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ void qSlicerDICOMExportDialog::onExport()
{
// Save to temporary folder and store files in database directory when adding
outputFolder.setPath(qSlicerApplication::application()->temporaryPath());
QString tempSubDirName = QString("DICOMExportTemp_%1").arg(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));

// Force using en-US locale, otherwise for example on a computer with
// Egyptian Arabic (ar-EG) locale, Arabic numerals may be used.
QLocale enUsLocale = QLocale(QLocale::English, QLocale::UnitedStates);
QString tempSubDirName = QString("DICOMExportTemp_%1").arg(enUsLocale.toString(QDateTime::currentDateTime(), "yyyyMMdd_hhmmss"));

outputFolder.mkdir(tempSubDirName);
outputFolder.cd(tempSubDirName);
}
Expand Down