Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/5971.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed case-sensitivity in isisimport on linux, now can succeed whether data file is upper or lowercase.
43 changes: 27 additions & 16 deletions isis/src/base/apps/isisimport/isisimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "OriginalLabel.h"
#include "OriginalXmlLabel.h"
#include "PvlToJSON.h"
#include "ProcessImport.h"
#include "TextFile.h"
#include "XmlToJson.h"

Expand All @@ -27,6 +26,14 @@ using json = nlohmann::json;

namespace Isis {

bool setFileIfExists(ProcessImport& fileImporter, FileName& fileName, const QString &ext) {
if(fileName.existsWithExt(ext)) {
fileImporter.SetInputFile(fileName.removeExtension().addExtension(ext).expanded());
Comment thread
jrcain-usgs marked this conversation as resolved.
Outdated
return true;
}
return false;
}

void isisimport(UserInterface &ui, Pvl *log) {
FileName fileTemplate = ("$ISISROOT/appdata/import/fileTemplate.tpl");
json jsonData;
Expand Down Expand Up @@ -347,22 +354,26 @@ namespace Isis {


ProcessImport importer;
if (inputFileName.removeExtension().addExtension("dat").fileExists()){
importer.SetInputFile(inputFileName.removeExtension().addExtension("dat").expanded());
}
else if (inputFileName.removeExtension().addExtension("img").fileExists()) {
importer.SetInputFile(inputFileName.removeExtension().addExtension("img").expanded());
}
else if (inputFileName.removeExtension().addExtension("QUB").fileExists()) {
importer.SetInputFile(inputFileName.removeExtension().addExtension("QUB").expanded());
}
else if (inputFileName.removeExtension().addExtension("tif").fileExists()) {
QString msg = "GeoTIFFs may contain ancillary data that isisimport cannot process. "
"Please convert the .TIF to a cube using another tool, such as gdal_translate.";
throw IException(IException::User, msg, _FILEINFO_);
Comment thread
jrcain-usgs marked this conversation as resolved.
importer.SetInputFile(inputFileName.expanded());

// Check for files that match the from= file, except with these file extensions.
// If found, replace the data filename to import. Check upper and lower cases for linux compatibility.
QString fileExtensions[] = {"dat", "img", "qub"};
bool foundDataFile = false;

for (const QString& ext : fileExtensions) {
foundDataFile = setFileIfExists(importer, inputFileName, ext);
if (foundDataFile) break;
foundDataFile = setFileIfExists(importer, inputFileName, ext.toUpper());
if (foundDataFile) break;
}
else {
importer.SetInputFile(inputFileName.expanded());

if (!foundDataFile) {
if (inputFileName.existsWithExt("tif") || inputFileName.existsWithExt("TIF")) {
QString msg = "GeoTIFFs may contain ancillary data that isisimport cannot process. "
"Please convert the .TIF to a cube using another tool, such as gdal_translate.";
throw IException(IException::User, msg, _FILEINFO_);
}
}

// Use inja to get number of lines, samples, and bands from the input label
Expand Down
2 changes: 2 additions & 0 deletions isis/src/base/apps/isisimport/isisimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include "Pvl.h"
#include "UserInterface.h"
#include "ProcessImport.h"
Comment thread
jrcain-usgs marked this conversation as resolved.
Outdated

namespace Isis {
bool setFileIfExists(ProcessImport& fileImporter, FileName& fileName, const QString &ext);
extern void isisimport(UserInterface &ui, Pvl *log=nullptr);
}

Expand Down
1 change: 1 addition & 0 deletions isis/src/core/include/FileName.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace Isis {
FileName addExtension(const QString &extension) const;
FileName removeExtension() const;
FileName setExtension(const QString &extension) const;
bool existsWithExt(const QString &extension) const;
Comment thread
jrcain-usgs marked this conversation as resolved.
Outdated

bool isVersioned() const;
bool isNumericallyVersioned() const;
Expand Down
11 changes: 11 additions & 0 deletions isis/src/core/src/FileName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ namespace Isis {
return result;
}

/**
* Checks if the filename exists, but with the given extension instead of its own.
*
* @param ext The new file extension to check in place of any current file extension
*
* @return bool, true if file exists with given extension
*/
bool FileName::existsWithExt(const QString& ext) const {
return removeExtension().addExtension(ext).fileExists();
}

/**
* Checks to see if a file name is versioned by date or numerically. Returns true if file is
* versioned by date or numerically; returns false otherwise.
Expand Down
Loading