Skip to content

Commit

Permalink
Fix setEof/setFileTime exceptions (#16)
Browse files Browse the repository at this point in the history
* Fixed Exception when setEof is called on not yet opened file

* Fixed Exception on setFileTime on currently opened file

* Cleanup
  • Loading branch information
dedmen authored Sep 11, 2019
1 parent 64448dd commit b22eac6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion DokanPbo.Core/PboFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void DeleteNode(string filename)

private IPboFsNode GetNodeFast(string filename, DokanFileInfo info)
{
if (info.Context is IPboFsNode node)
if (info?.Context is IPboFsNode node)
return node;
return FindNode(filename);
}
Expand Down Expand Up @@ -564,6 +564,8 @@ public NtStatus SetFileTime(string filename, DateTime? ctime, DateTime? atime, D

if (node is PboFsRealFile file)
{
//#TODO we can't do this while file is open. Optimally we just want to queue tasks to be executed once the file is closed.
if (file.IsOpenForWriting) return DokanResult.Success;
if (ctime != null)
{
System.IO.File.SetCreationTime(file.GetRealPath(), ctime.Value);
Expand Down
6 changes: 4 additions & 2 deletions DokanPbo.Core/PboFSNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DokanNet;
using DokanNet;
using SwiftPbo;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -277,9 +277,10 @@ public class PboFsRealFile : IPboFsFile, IPboFsRealObject
{
public System.IO.FileInfo file;
private bool? wantsOpenWrite;
private FileMode openMode;
private FileMode openMode = FileMode.Open;
private System.IO.FileStream readStream = null;
private System.IO.FileStream writeStream = null;
public bool IsOpenForWriting => writeStream != null;

//In case someone tries to set lastWriteTime while we have a Write stream open.
private DateTime? lastWriteTimeTodo;
Expand All @@ -300,6 +301,7 @@ public PboFsRealFile(System.IO.FileInfo inputFile, PboFsFolder inputParent) : ba
};
}

//writeableStream is from newly created file
public PboFsRealFile(System.IO.FileInfo inputFile, PboFsFolder inputParent, System.IO.FileStream writeableStream) : this(inputFile, inputParent)
{
writeStream = writeableStream;
Expand Down

0 comments on commit b22eac6

Please sign in to comment.