Skip to content

Commit 623c415

Browse files
Fix File.Length to refresh file metadata and reflect updated file size (#1148)
* Fixed GxFileInfo.Length to refresh file metadata and reflect updated file size * Fix unit test. * Fix unit test. * Removed the LastModified assertion from the test, as it can fail when the test executes too quickly and timestamps match unexpectedly.
1 parent 8d11092 commit 623c415

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

dotnet/src/dotnetframework/GxClasses/Domain/GXFileIO.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public DateTime LastWriteTime
260260
{
261261
get
262262
{
263+
_file.Refresh();
263264
return _file.LastWriteTime;
264265
}
265266
}
@@ -268,7 +269,8 @@ public long Length
268269
{
269270
get
270271
{
271-
return _file.Length;
272+
_file.Refresh();
273+
return _file.Length;
272274
}
273275
}
274276

dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Runtime.InteropServices;
4+
using System.Threading;
45
using DotNetUnitTest;
56
using GeneXus.Configuration;
67
using GeneXus.Printer;
@@ -154,6 +155,25 @@ public void ReportUtilAddPathWithIllegalCharacters()
154155

155156
Assert.Equal(name, fullPath);
156157
}
158+
[Fact]
159+
public void Length_ShouldUpdate_WhenFileChanges()
160+
{
161+
GxFile gxFile = new GxFile(BaseDir);
162+
gxFile.Source = "FileChanges.txt";
163+
gxFile.Delete();
164+
165+
gxFile.Open(string.Empty);
166+
gxFile.WriteLine("Initial content");
167+
gxFile.Close();
157168

169+
long initialLength = gxFile.GetLength();
170+
171+
gxFile.Open(string.Empty);
172+
gxFile.WriteLine("Additional content");
173+
gxFile.Close();
174+
175+
long updatedLength = gxFile.GetLength();
176+
Assert.NotEqual(initialLength, updatedLength);
177+
}
158178
}
159179
}

0 commit comments

Comments
 (0)