Skip to content

Commit

Permalink
Fix Null Time Stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyangwx committed Oct 26, 2023
1 parent 384f3c8 commit b95faed
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
42 changes: 35 additions & 7 deletions LTFSCopyGUI/FTPService.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Public Class FTPService
Public Services As ServiceCollection
Public ftpServerHost As IFtpServerHost

Public Event LogPrint(s As String)
Public MustInherit Class LTFSFileSystemEntry
Implements IUnixFileSystemEntry
Public AccMode As New Generic.GenericAccessMode(True, False, True)
Expand All @@ -34,14 +35,22 @@ Public Class FTPService
End Sub
Public Sub New(fsInfo As ltfsindex.file)
FileInfo = fsInfo
LastWriteTime = New DateTimeOffset(ParseTimeStamp(fsInfo.changetime))
CreatedTime = New DateTimeOffset(ParseTimeStamp(fsInfo.creationtime))
Try
CreatedTime = New DateTimeOffset(ParseTimeStamp(fsInfo.creationtime))
LastWriteTime = New DateTimeOffset(ParseTimeStamp(fsInfo.changetime))
Catch ex As Exception

End Try
Name = fsInfo.name
End Sub
Public Sub New(fsInfo As ltfsindex.directory)
DirectoryInfo = fsInfo
LastWriteTime = New DateTimeOffset(ParseTimeStamp(fsInfo.changetime))
CreatedTime = New DateTimeOffset(ParseTimeStamp(fsInfo.creationtime))
Try
CreatedTime = New DateTimeOffset(ParseTimeStamp(fsInfo.creationtime))
LastWriteTime = New DateTimeOffset(ParseTimeStamp(fsInfo.changetime))
Catch ex As Exception

End Try
Name = fsInfo.name
End Sub
Public ReadOnly Property Name As String Implements IUnixFileSystemEntry.Name
Expand Down Expand Up @@ -115,12 +124,17 @@ Public Class FTPService
Public Property TapeDrive As String
Public Property BlockSize As Integer = 524288
Public Property ExtraPartitionCount As Integer = 1
Public Sub New(rootPath As ltfsindex.directory, ByVal drive As String, ByVal blksize As Integer, ByVal _extraPartitionCount As Integer)
Public Event LogPrint(s As String)
Public Sub New(rootPath As ltfsindex.directory, ByVal drive As String, ByVal blksize As Integer, ByVal _extraPartitionCount As Integer, Optional ByVal LogHandler As Action(Of String) = Nothing)
FileSystemEntryComparer = StringComparer.OrdinalIgnoreCase
Root = New LTFSDirectoryEntry(rootPath, True)
TapeDrive = drive
BlockSize = blksize
ExtraPartitionCount = _extraPartitionCount
If LogHandler IsNot Nothing Then AddHandler LogPrint,
Sub(s As String)
LogHandler(s)
End Sub
End Sub

Public ReadOnly Property SupportsAppend As Boolean Implements IUnixFileSystem.SupportsAppend
Expand Down Expand Up @@ -182,7 +196,11 @@ Public Class FTPService

Public Function OpenReadAsync(fileEntry As IUnixFileEntry, startPosition As Long, cancellationToken As CancellationToken) As Task(Of Stream) Implements IUnixFileSystem.OpenReadAsync
Dim fileInfo As ltfsindex.file = CType(fileEntry, LTFSFileEntry).FileInfo
RaiseEvent LogPrint($"OpenReadAsync file={fileInfo.name} position={startPosition}")
Dim input As New IOManager.LTFSFileStream(fileInfo, TapeDrive, BlockSize, ExtraPartitionCount)
AddHandler input.LogPrint, Sub(s As String)
RaiseEvent LogPrint(s)
End Sub
Dim rstream As New BufferedStream(input, 134217728)
rstream.Seek(startPosition, SeekOrigin.Begin)
Return Task.FromResult(Of Stream)(rstream)
Expand Down Expand Up @@ -210,21 +228,24 @@ Public Class FTPService
Private ReadOnly Property _drive As String
Private ReadOnly Property _blocksize As Integer
Private ReadOnly Property _extraPartitionCount As Integer
Public ReadOnly Property LogHandler As Action(Of String)
Public Sub New(options As Microsoft.Extensions.Options.IOptions(Of LTFSFileSystemOptions))
_root = options.Value.Root
_drive = options.Value.TapeDrive
_blocksize = options.Value.BlockSize
_extraPartitionCount = options.Value.ExtraPartitionCount
LogHandler = options.Value.LogHandler
End Sub
Public Function Create(accountInformation As IAccountInformation) As Task(Of IUnixFileSystem) Implements IFileSystemClassFactory.Create
Return Task.FromResult(Of IUnixFileSystem)(New LTFSFileSystem(_root, _drive, _blocksize, _extraPartitionCount))
Return Task.FromResult(Of IUnixFileSystem)(New LTFSFileSystem(_root, _drive, _blocksize, _extraPartitionCount, LogHandler))
End Function
End Class
Public Class LTFSFileSystemOptions
Public Property Root As ltfsindex.directory
Public Property TapeDrive As String
Public Property BlockSize As Integer
Public Property ExtraPartitionCount As Integer
Public Property LogHandler As Action(Of String)
End Class
Public Shared Function UseLTFSFileSystem(builder As IFtpServerBuilder) As IFtpServerBuilder
builder.Services.AddSingleton(Of IFileSystemClassFactory, LTFSFileSystemProvider)()
Expand Down Expand Up @@ -265,6 +286,9 @@ Public Class FTPService
opt.TapeDrive = TapeDrive
opt.BlockSize = BlockSize
opt.ExtraPartitionCount = ExtraPartitionCount
opt.LogHandler = Sub(s As String)
RaiseEvent LogPrint(s)
End Sub
End Sub)

Services.AddFtpServer(
Expand All @@ -290,7 +314,11 @@ Public Class FTPService
End Sub
Public Shared Function ParseTimeStamp(t As String) As Date
'yyyy-MM-ddTHH:mm:ss.fffffff00Z
Return Date.ParseExact(t, "yyyy-MM-ddTHH:mm:ss.fffffff00Z", Globalization.CultureInfo.InvariantCulture)
Try
Return Date.ParseExact(t, "yyyy-MM-ddTHH:mm:ss.fffffff00Z", Globalization.CultureInfo.InvariantCulture)
Catch ex As Exception
Return New Date()
End Try
End Function

End Class
11 changes: 10 additions & 1 deletion LTFSCopyGUI/IOManager.vb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ Public Class IOManager

Public Class LTFSFileStream
Inherits Stream
Public Event LogPrint(s As String)
Public ReadOnly Property FileInfo As ltfsindex.file
Public Property TapeDrive As String
Public Property BlockSize As Integer
Expand Down Expand Up @@ -726,7 +727,13 @@ Public Class IOManager
If value < 0 Then value = 0
If value >= FileInfo.length Then value = FileInfo.length - 1
Dim ext As ltfsindex.file.extent = GetExtent(value)
TapeUtils.Locate(TapeDrive, ext.startblock + (Position - ext.fileoffset) \ BlockSize, Math.Min(ExtraPartitionCount, ext.partition))
Dim p As New TapeUtils.PositionData(TapeDrive)
Dim targetBlock As Long = ext.startblock + (value - ext.fileoffset) \ BlockSize
Dim targetPartition As Integer = Math.Min(ExtraPartitionCount, ext.partition)
If p.BlockNumber <> targetBlock OrElse p.PartitionNumber <> targetPartition Then
RaiseEvent LogPrint($"LOCATE {TapeDrive} B{targetBlock}P{targetPartition} (File position {value})")
TapeUtils.Locate(TapeDrive, targetBlock, targetPartition)
End If
_Position = value
End SyncLock
End Set
Expand All @@ -746,6 +753,7 @@ Public Class IOManager

Public Overrides Function Seek(offset As Long, origin As SeekOrigin) As Long
SyncLock ReadLock
RaiseEvent LogPrint($"Seek Offset {offset} Origin {origin}")
Select Case origin
Case SeekOrigin.Begin
Position = offset
Expand All @@ -760,6 +768,7 @@ Public Class IOManager
Public Shared ReadLock As New Object
Public Overrides Function Read(buffer() As Byte, offset As Integer, count As Integer) As Integer
SyncLock ReadLock
RaiseEvent LogPrint($"ReadFile: Offset {offset} Count{count}")
Dim rBytes As Integer = 0
Dim fCurrentPos As Long = Position
Dim CUrrentP As Integer = New TapeUtils.PositionData(TapeDrive).PartitionNumber
Expand Down
4 changes: 3 additions & 1 deletion LTFSCopyGUI/LTFSWriter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4021,7 +4021,9 @@ Public Class LTFSWriter

Private Sub 启动FTP服务只读ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 启动FTP服务只读ToolStripMenuItem.Click
Dim svc As New FTPService()

AddHandler svc.LogPrint, Sub(s As String)
PrintMsg($"FTPSVC> {s}")
End Sub
svc.port = Integer.Parse(InputBox("Port", "FTP Service", "8021"))
svc.schema = schema
svc.TapeDrive = TapeDrive
Expand Down

0 comments on commit b95faed

Please sign in to comment.