public void AddDirectory(string handle, string hostPath, ConflictPolicy policy) { var pathParts = handle.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); var currentDirectory = mRoot; int i = 0; for ( ; i < pathParts.Length; ++i) { string part = pathParts[i]; if (!currentDirectory.Entries.TryGetValue(part, out var foundEntry)) { break; } if (foundEntry.Kind != FileSystemEntryKind.Directory) { throw new DirectoryNotFoundException("Path of path does not exist"); } currentDirectory = ( DirectoryEntry )foundEntry; } for ( ; i < pathParts.Length; ++i) { var newDirectory = new DirectoryEntry(currentDirectory, pathParts[i], uint.MaxValue); currentDirectory.Entries[newDirectory.Name] = newDirectory; currentDirectory = newDirectory; } }
public void AddFile(int handle, Stream stream, bool ownsStream, ConflictPolicy policy) { bool added = false; try { if (!Exists(handle)) { throw new NotSupportedException("This filesystem does not support adding new files"); } if (policy.Kind == ConflictPolicy.PolicyKind.ThrowError) { throw new FileExistsException <int>(handle); } mEntryMap[handle] = new MemoryEntry(handle, stream, ownsStream); added = true; } finally { if (!added && ownsStream) { stream.Dispose(); } } }
public void AddFile(string handle, Stream stream, bool ownsStream, ConflictPolicy policy) { if (Exists(handle)) { switch (policy.Kind) { case ConflictPolicy.PolicyKind.ThrowError: throw new FileExistsException <string>(handle); case ConflictPolicy.PolicyKind.Ignore: return; } } mEntryMap[handle] = new MemoryEntry(stream, ownsStream, handle); }
public void AddFile(int handle, string hostPath, ConflictPolicy policy) { var stream = File.OpenRead(hostPath); bool result = false; try { result = TryAddFile(handle, stream, true, policy); } finally { if (!result) { stream.Dispose(); } } }
public void AddFile(string handle, Stream stream, bool ownsStream, ConflictPolicy policy) { var directoryPath = Path.GetDirectoryName(handle); DirectoryEntry directory; if (!string.IsNullOrWhiteSpace(directoryPath)) { AddDirectory(directoryPath, policy); if (!TryFindDirectory(directoryPath, out directory)) { throw new DirectoryNotFoundException("Part of path doesn't exist"); } } else { directory = mRoot; } var fileName = Path.GetFileName(handle); if (directory.Entries.TryGetValue(fileName, out var entry)) { switch (policy.Kind) { case ConflictPolicy.PolicyKind.ThrowError: throw new FileExistsException <string>(handle); case ConflictPolicy.PolicyKind.Replace: // Handled after this code break; case ConflictPolicy.PolicyKind.Ignore: return; default: throw new ArgumentOutOfRangeException(nameof(policy)); } } directory.Entries[fileName] = new MemoryFileEntry(directory, stream, ownsStream, fileName); }
private bool TryAddFile(int handle, Stream stream, bool ownsStream, ConflictPolicy policy) { if (mEntryMap.TryGetValue(handle, out _)) { switch (policy.Kind) { case ConflictPolicy.PolicyKind.ThrowError: throw new FileExistsException <int>(handle); case ConflictPolicy.PolicyKind.Replace: // Handled later break; case ConflictPolicy.PolicyKind.Ignore: return(false); } } mEntryMap[handle] = new MemoryEntry(handle, stream, ownsStream); return(true); }
public void AddFile(int handle, string hostPath, ConflictPolicy policy) { AddFile(handle, File.OpenRead(hostPath), true, policy); }
public void AddDirectory(int handle, string hostPath, ConflictPolicy policy) { throw new NotSupportedException("This filesystem does not support directories"); }
public void AddDirectory(string handle, ConflictPolicy policy) { AddDirectory(handle, null, policy); }
public void AddFile(int handle, Stream stream, bool ownsStream, ConflictPolicy policy) { TryAddFile(handle, stream, ownsStream, policy); }
public void AddFile(int handle, short userId, Stream stream, bool ownsStream, ConflictPolicy policy) { bool replacing = false; if (mEntryMap.TryGetValue(handle, out var foundEntry)) { switch (policy.Kind) { case ConflictPolicy.PolicyKind.ThrowError: throw new FileExistsException <int>(handle); case ConflictPolicy.PolicyKind.Replace: // Handled later replacing = true; break; case ConflictPolicy.PolicyKind.Ignore: return; default: throw new ArgumentOutOfRangeException(nameof(policy)); } } bool compressed = false; Entry entry; var entryStream = stream; if (compressed) { var compression = new LBCompression(); entryStream = compression.Compress(stream); ownsStream = true; } if (!replacing) { var fileStream = stream as FileStream ?? throw new NotSupportedException("Can't add files without filename information to this file system"); var extension = Path.GetExtension(fileStream.Name); if (extension == null) { throw new NotSupportedException("Can't add files without file extension information to this file system"); } entry = new MemoryEntry(handle, entryStream, ownsStream, 1, compressed, ( int )stream.Length, userId, extension .ToUpper() .TrimStart('.')); } else { entry = new MemoryEntry(foundEntry.Handle, entryStream, ownsStream, foundEntry.Type, compressed, ( int )stream.Length, foundEntry.UserId, foundEntry.Extension); } mEntryMap[entry.Handle] = entry; }
public void AddFile(string handle, Stream stream, bool ownsStream, ConflictPolicy policy) { using (var fileStream = File.Create(Path.Combine(RootDirectory, handle))) stream.CopyTo(fileStream); }
public void AddFile(string handle, string hostPath, ConflictPolicy policy) { File.Copy(hostPath, Path.Combine(RootDirectory, handle), policy.Kind == ConflictPolicy.PolicyKind.Replace); }
public void AddDirectory(string handle, string hostPath, ConflictPolicy policy) { Directory.CreateDirectory(Path.Combine(RootDirectory, handle)); }
public void AddFile(string handle, string hostPath, ConflictPolicy policy) { var stream = File.OpenRead(hostPath); AddFile(handle, stream, true, policy); }