mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-04-29 18:27:48 +02:00
NTFileSystemAdapter: Bugfix: FILE_OPEN_IF was not handled properly if the file exists
This commit is contained in:
parent
dae8a6b19e
commit
340f55c26e
1 changed files with 63 additions and 48 deletions
|
@ -157,62 +157,77 @@ namespace SMBLibrary
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fileStatus = FileStatus.FILE_EXISTS;
|
fileStatus = FileStatus.FILE_EXISTS;
|
||||||
if (!requestedWriteAccess)
|
if (createDisposition == CreateDisposition.FILE_OPEN_IF)
|
||||||
{
|
{
|
||||||
return NTStatus.STATUS_ACCESS_DENIED;
|
if (entry.IsDirectory && forceFile)
|
||||||
}
|
|
||||||
|
|
||||||
if (createDisposition == CreateDisposition.FILE_OVERWRITE ||
|
|
||||||
createDisposition == CreateDisposition.FILE_OVERWRITE_IF)
|
|
||||||
{
|
|
||||||
// Truncate the file
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Stream temp = m_fileSystem.OpenFile(path, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite);
|
return NTStatus.STATUS_FILE_IS_A_DIRECTORY;
|
||||||
temp.Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
NTStatus status = ToNTStatus(ex);
|
|
||||||
Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
fileStatus = FileStatus.FILE_OVERWRITTEN;
|
|
||||||
}
|
|
||||||
else if (createDisposition == CreateDisposition.FILE_SUPERSEDE)
|
|
||||||
{
|
|
||||||
// Delete the old file
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_fileSystem.Delete(path);
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
NTStatus status = ToNTStatus(ex);
|
|
||||||
Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (!entry.IsDirectory && forceDirectory)
|
||||||
{
|
{
|
||||||
if (forceDirectory)
|
return NTStatus.STATUS_OBJECT_PATH_INVALID;
|
||||||
{
|
|
||||||
Log(Severity.Information, "CreateFile: Creating directory '{0}'", path);
|
|
||||||
entry = m_fileSystem.CreateDirectory(path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log(Severity.Information, "CreateFile: Creating file '{0}'", path);
|
|
||||||
entry = m_fileSystem.CreateFile(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!requestedWriteAccess)
|
||||||
{
|
{
|
||||||
NTStatus status = ToNTStatus(ex);
|
return NTStatus.STATUS_ACCESS_DENIED;
|
||||||
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
}
|
||||||
return status;
|
|
||||||
|
if (createDisposition == CreateDisposition.FILE_OVERWRITE ||
|
||||||
|
createDisposition == CreateDisposition.FILE_OVERWRITE_IF)
|
||||||
|
{
|
||||||
|
// Truncate the file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Stream temp = m_fileSystem.OpenFile(path, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||||
|
temp.Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error truncating '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
fileStatus = FileStatus.FILE_OVERWRITTEN;
|
||||||
|
}
|
||||||
|
else if (createDisposition == CreateDisposition.FILE_SUPERSEDE)
|
||||||
|
{
|
||||||
|
// Delete the old file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_fileSystem.Delete(path);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error deleting '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (forceDirectory)
|
||||||
|
{
|
||||||
|
Log(Severity.Information, "CreateFile: Creating directory '{0}'", path);
|
||||||
|
entry = m_fileSystem.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log(Severity.Information, "CreateFile: Creating file '{0}'", path);
|
||||||
|
entry = m_fileSystem.CreateFile(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
NTStatus status = ToNTStatus(ex);
|
||||||
|
Log(Severity.Verbose, "CreateFile: Error creating '{0}'. {1}.", path, status);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
fileStatus = FileStatus.FILE_SUPERSEDED;
|
||||||
}
|
}
|
||||||
fileStatus = FileStatus.FILE_SUPERSEDED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue