Skip to content

Commit

Permalink
need to use windows slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaskueffel committed Aug 28, 2023
1 parent 5ed4a0f commit 23d7eb6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions SyncProviders/SmbLibProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ string DestinationPath
{
get
{
return JobOptions.DestinationPath.Substring(JobOptions.DestinationPath.IndexOf(Share) + Share.Length);
return JobOptions.DestinationPath.Substring(JobOptions.DestinationPath.IndexOf(Share) + Share.Length).Replace('/','\\');
}
}

Expand All @@ -66,20 +66,20 @@ public override void SyncSourceToDest()
}
if (JobOptions.SyncDeleted)
{
var files = ListFiles(DestinationPath, true);
foreach(var file in files)
var remoteFiles = ListFiles(DestinationPath, true);
foreach(var file in remoteFiles)
{
var realFilePath = file.Substring(file.IndexOf(DestinationPath) + DestinationPath.Length).Trim('/', '\\');
if (!_fi.Any(x => x.FullName.EndsWith(realFilePath)))
var realFilePath = file.Substring(file.IndexOf(DestinationPath) + DestinationPath.Length).Trim('\\').Replace('/', '\\');
if (!_fi.Any(x => x.FullName.Replace('/', '\\').EndsWith(realFilePath)))
DeleteFile(file);
}
}
foreach (FileInfo f in _fi)
{
bool copy = false;
var relativeFilename = f.FullName.Substring(Path.GetFullPath(JobOptions.SourcePath).Length);
var remotefile = Path.Combine(DestinationPath, relativeFilename.TrimStart('\\'));
var exists = FileExists(remotefile.Trim('/', '\\'), out long size);
var remotefile = Path.Combine(DestinationPath, relativeFilename.TrimStart('\\', '/')).Replace('/', '\\');
var exists = FileExists(remotefile, out long size);
copy = !exists || size != f.Length;
if (copy)
{
Expand Down Expand Up @@ -137,7 +137,7 @@ public void WriteFile(string localFilePath, string remoteFilePath)
FileStatus fileStatus;
//Create folders recursive

var paths = remoteFilePath.Trim('/', '\\').Split('/', '\\');
var paths = remoteFilePath.Trim('\\').Split('\\');
if (paths.Length > 1)
{
string createpath = "";
Expand All @@ -152,7 +152,7 @@ public void WriteFile(string localFilePath, string remoteFilePath)
}
}

status = fileStore.CreateFile(out fileHandle, out fileStatus, remoteFilePath.Trim('/','\\'), AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_SUPERSEDE, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
status = fileStore.CreateFile(out fileHandle, out fileStatus, remoteFilePath.Trim('\\'), AccessMask.GENERIC_WRITE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_SUPERSEDE, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
if (status == NTStatus.STATUS_SUCCESS)
{
int writeOffset = 0;
Expand Down Expand Up @@ -181,7 +181,7 @@ void DeleteFile(string filePath)
{
object fileHandle;
FileStatus fileStatus;
var status = fileStore.CreateFile(out fileHandle, out fileStatus, filePath.Trim('/','\\'), AccessMask.GENERIC_WRITE | AccessMask.DELETE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_OPEN, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);
var status = fileStore.CreateFile(out fileHandle, out fileStatus, filePath.Trim('\\'), AccessMask.GENERIC_WRITE | AccessMask.DELETE | AccessMask.SYNCHRONIZE, FileAttributes.Normal, ShareAccess.None, CreateDisposition.FILE_OPEN, CreateOptions.FILE_NON_DIRECTORY_FILE | CreateOptions.FILE_SYNCHRONOUS_IO_ALERT, null);

if (status == NTStatus.STATUS_SUCCESS)
{
Expand All @@ -198,7 +198,7 @@ List<string> ListFiles(string subPath, bool recurse)
List<string> retval = new List<string>();
object directoryHandle;
FileStatus fileStatus;
var status = fileStore.CreateFile(out directoryHandle, out fileStatus, subPath.Trim('/', '\\'), AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
var status = fileStore.CreateFile(out directoryHandle, out fileStatus, subPath.Trim('\\'), AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
if (status == NTStatus.STATUS_SUCCESS)
{
List<QueryDirectoryFileInformation> fileList;
Expand All @@ -217,14 +217,14 @@ List<string> ListFiles(string subPath, bool recurse)
{
try
{
retval.AddRange(ListFiles(Path.Combine(subPath.Trim('/', '\\'), file.FileName), recurse));
retval.AddRange(ListFiles(Path.Combine(subPath.Trim('\\'), file.FileName), recurse));
}
catch { }
}
}
else
{
retval.Add(Path.Combine(subPath.Trim('/', '\\'), file.FileName));
retval.Add(Path.Combine(subPath.Trim('\\'), file.FileName));
}

}
Expand All @@ -239,7 +239,7 @@ bool FileExists(string filepathFromShare, out long size)
{
object directoryHandle;
FileStatus fileStatus;
var status = fileStore.CreateFile(out directoryHandle, out fileStatus, filepathFromShare.Trim('/', '\\'), AccessMask.GENERIC_READ, FileAttributes.Normal, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_NON_DIRECTORY_FILE, null);
var status = fileStore.CreateFile(out directoryHandle, out fileStatus, filepathFromShare.Trim('\\'), AccessMask.GENERIC_READ, FileAttributes.Normal, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_NON_DIRECTORY_FILE, null);
if (status == NTStatus.STATUS_SUCCESS)
{
status = fileStore.GetFileInformation(out FileInformation result, directoryHandle, FileInformationClass.FileStandardInformation);
Expand Down

0 comments on commit 23d7eb6

Please sign in to comment.