Skip to content

Commit

Permalink
Better handling of zero size files
Browse files Browse the repository at this point in the history
  • Loading branch information
yogilad committed Nov 4, 2023
1 parent 317638a commit aeb6512
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
6 changes: 6 additions & 0 deletions Src/App/Workers/Ingest/TempTableWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public override async Task HandleFilesAsync(List<string> filesAndFolders, string
foreach (var path in FileHelper.ExpandDropFileList(filesAndFolders))
{
var fileInfo = new FileInfo(path);

if (fileInfo.Length == 0)
{
continue;
}

var formatResult = FileHelper.GetFormatFromFileName(fileInfo.Name);
var upstreamFileName = FileHelper.CreateUploadFileName(fileInfo.Name);

Expand Down
61 changes: 38 additions & 23 deletions Src/App/Workers/Misc/InspectSchemaWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,49 @@ public override async Task HandleFilesAsync(List<string> filesAndFolders, string
foreach (var filePath in fileList)
{
var fileInfo = new FileInfo(filePath);
var formatResult = FileHelper.GetFormatFromFileName(fileInfo.Name);
var upstreamFileName = FileHelper.CreateUploadFileName(fileInfo.Name);
using var fileStream = File.OpenRead(filePath);
var result = await HandleSingleTextStreamAsync(databaseHelper, fileStream, formatResult, upstreamFileName, firstRowIsHeader, filePath);
var escapedSchema = string.Empty;
var escapedError = string.Empty;

if (result.Schema != null)

if (fileInfo.Length == 0)
{
escapedSchema = Regex.Replace(result.Schema.ToSchemaString(detectionMode), @"\p{Cc}", a => string.Format("[{0:X2}]", (byte)a.Value[0]));
curFileNo++;
report.Append(curFileNo);
report.Append("\t");
report.Append(filePath);
report.Append("\t");
report.Append("\t");
report.Append("\t");
report.AppendLine("File is empty");
}

if (result.Error != null)
else
{
escapedError = Regex.Replace(result.Error, @"\p{Cc}", a => string.Format("[{0:X2}]", (byte)a.Value[0]));
var formatResult = FileHelper.GetFormatFromFileName(fileInfo.Name);
var upstreamFileName = FileHelper.CreateUploadFileName(fileInfo.Name);
using var fileStream = File.OpenRead(filePath);
var result = await HandleSingleTextStreamAsync(databaseHelper, fileStream, formatResult, upstreamFileName, firstRowIsHeader, filePath);
var escapedSchema = string.Empty;
var escapedError = string.Empty;

if (result.Schema != null)
{
escapedSchema = Regex.Replace(result.Schema.ToSchemaString(detectionMode), @"\p{Cc}", a => string.Format("[{0:X2}]", (byte)a.Value[0]));
}

if (result.Error != null)
{
escapedError = Regex.Replace(result.Error, @"\p{Cc}", a => string.Format("[{0:X2}]", (byte)a.Value[0]));
}

curFileNo++;
report.Append(curFileNo);
report.Append("\t");
report.Append(filePath);
report.Append("\t");
report.Append(result.Format);
report.Append("\t");
report.Append(escapedSchema);
report.Append("\t");
report.AppendLine(escapedError);
}

curFileNo++;
report.Append(curFileNo);
report.Append("\t");
report.Append(filePath);
report.Append("\t");
report.Append(result.Format);
report.Append("\t");
report.Append(escapedSchema);
report.Append("\t");
report.AppendLine(escapedError);

progressNotification.UpdateProgress("Inspecting Files", curFileNo / fileList.Count, $"{curFileNo}/{fileList.Count}");
}

Expand Down

0 comments on commit aeb6512

Please sign in to comment.