/// <summary> /// Creates a virtual file with the Physical location information in it. /// </summary> /// <param name="vp">The vp.</param> VirtualFile CreateAndWriteVirtualFile(VirtualPath vp) { ShadowFullPath readPath = _pathFactory.CreateShadowFullPath4Read(vp); ShadowFullPath writePath = _pathFactory.CreateShadwoFullPath4Write(vp); var virtualFile = new VirtualFile() { PhysicalUri = new Uri(writePath.PathString) }; IOUtil.PrepareParentDirForPath(readPath.PathString); XmlUtil.WriteXml <VirtualFile>(virtualFile, readPath.PathString); Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format("A virtual file is created at {0}", readPath.PathString)); return(virtualFile); }
/// <summary> /// Copies the file at the given path to the server, which could be anywhere from /// the local machine to a remote one. /// </summary> /// <param name="virtualPath">The virtual path.</param> public void CopyToServer(VirtualPath virtualPath) { var fromFullPath = _pathFactory.CreateShadwoFullPath4Write(virtualPath); byte[] infoBytes = _serverProxy.Get(new Uri("/BitTorrent/Info")); var infoObj = XmlUtil.FromXml <BitTorrentServiceInfo>( Encoding.UTF8.GetString(infoBytes)); if (infoObj.ServerCacheUri.IsLoopback) { // Server on the same machine, we copy from file system. var relativePath = virtualPath.PathString.Substring( virtualPath.PathString.IndexOf(Path.DirectorySeparatorChar, 1)); var toFullPath = UriUtil.CombinePaths(infoObj.ServerCacheUri.LocalPath, new Uri(relativePath, UriKind.Relative)); IOUtil.PrepareParentDirForPath(toFullPath); if (SysEnvironment.OSVersion == OS.Unix) { // In case of Unix, we actually use symbolic link instead of copying. var symlink = new UnixSymbolicLinkInfo(toFullPath); Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format( "Creating Symlink: {0} -> {1}", toFullPath, fromFullPath.PathString)); // Linking toPath to fromPath == Copy fromPath to toPath. symlink.CreateSymbolicLinkTo(fromFullPath.PathString); } else { throw new NotImplementedException("Only Unix hosts are currently supported."); } } else { throw new NotImplementedException("Only local machine is currently supported."); } }