Skip to content

Commit

Permalink
Check if file is datafile before download. Refs #8126.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Oct 24, 2013
1 parent 7b26175 commit 68d08d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ namespace Mantid
void exec();
/// get location of data file or download method
int doDownload( ICATPortBindingProxy & icat);
/// True if the stream is considered binary, false otherwise
bool isBinary(std::istream& stream);
/// True if the extension of the file is a datafile.
bool isDataFile(const std::string& fileName);
/// Saves the downloaded file to disc
std::string saveFiletoDisk(std::istream& rs,const std::string &fileName);
/// Saves downloaded file to local disk
Expand Down
27 changes: 19 additions & 8 deletions Code/Mantid/Framework/ICat/src/CatalogDownloadDataFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ if the data archive is not accessible, it downloads the files from the data serv
#include "MantidAPI/ICatalog.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/FileDescriptor.h"

#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
Expand Down Expand Up @@ -157,13 +156,25 @@ namespace Mantid
}

/**
* Checks to see if the file to be downloaded is a datafile.
* @param stream :: input stream
* @returns True if the stream is not considered ASCII (e.g. binary), false otherwise
*/
bool CatalogDownloadDataFiles::isBinary(std::istream& stream)
* Checks to see if the file to be downloaded is a datafile.
* @param fileName :: Name of data file to download.
* @returns True if the file is a data file.
*/
bool CatalogDownloadDataFiles::isDataFile(const std::string & fileName)
{
return !FileDescriptor::isAscii(stream);
std::string extension = Poco::Path(fileName).getExtension();
std::transform(extension.begin(),extension.end(),extension.begin(),tolower);

std::cerr << "The extension of this file is: " << extension << "\n";

if (extension.compare("raw") == 0 || extension.compare("nxs") == 0)
{
return true;
}
else
{
return false;
}
}

/**
Expand Down Expand Up @@ -232,7 +243,7 @@ namespace Mantid
Poco::Path path(downloadPath, fileName);
std::string filepath = path.toString();

std::ios_base::openmode mode = isBinary(rs) ? std::ios_base::binary : std::ios_base::out;
std::ios_base::openmode mode = isDataFile(fileName) ? std::ios_base::binary : std::ios_base::out;

std::ofstream ofs(filepath.c_str(), mode);
if ( ofs.rdstate() & std::ios::failbit )
Expand Down

0 comments on commit 68d08d6

Please sign in to comment.