private Dictionary <string, string> GetSourceNames(Duplicati.Server.Serialization.Interface.IBackup backup) { var systemIO = Duplicati.Library.Snapshots.SnapshotUtility.SystemIO; return(backup.Sources.Distinct().Select(x => { var sp = SpecialFolders.TranslateToDisplayString(x); if (sp != null) { return new KeyValuePair <string, string>(x, sp); } x = SpecialFolders.ExpandEnvironmentVariables(x); try { var nx = x; if (nx.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString())) { nx = nx.Substring(0, nx.Length - 1); } var n = systemIO.PathGetFileName(nx); if (!string.IsNullOrWhiteSpace(n)) { return new KeyValuePair <string, string>(x, n); } } catch { } if (x.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()) && x.Length > 1) { return new KeyValuePair <string, string>(x, x.Substring(0, x.Length - 1).Substring(x.Substring(0, x.Length - 1).LastIndexOf("/") + 1)); } else { return new KeyValuePair <string, string>(x, x); } }).ToDictionary(x => x.Key, x => x.Value)); }
private void Process(string command, string path, RequestInfo info) { if (string.IsNullOrEmpty(path)) { info.ReportClientError("No path parameter was found"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(info.Request.QueryString["onlyfolders"].Value, false); bool showHidden = Library.Utility.Utility.ParseBool(info.Request.QueryString["showhidden"].Value, false); string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { info.ReportClientError("The path parameter must start with a forward-slash"); return; } if (!string.IsNullOrWhiteSpace(command)) { if ("validate".Equals(command, StringComparison.OrdinalIgnoreCase)) { try { if (System.IO.Path.IsPathRooted(path) && (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))) { info.OutputOK(); return; } } catch { } info.ReportServerError("File or folder not found"); return; } else { info.ReportClientError(string.Format("No such operation found: {0}", command)); return; } } try { if (path != "" && path != "/") { path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); } IEnumerable <Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = DriveInfo.GetDrives() .Where(di => (di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable) && di.IsReady // Only try to create TreeNode entries for drives who were ready 'now' ) .Select(TryCreateTreeNodeForDrive) // This will try to create a TreeNode for selected drives .Where(tn => tn != null); // This filters out such entries that could not be created } else { res = ListFolderAsNodes(path, skipFiles, showHidden); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = res.Select(x => { x.resolvedpath = x.id; x.id = specialtoken + x.id.Substring(specialpath.Length); return(x); }); } // We have to resolve the query before giving it to OutputOK // If we do not do this, and the query throws an exception when OutputOK resolves it, // the exception would not be handled properly res = res.ToList(); info.OutputOK(res); } catch (Exception ex) { info.ReportClientError("Failed to process the path: " + ex.Message); } }
private void Process(string command, string path, RequestInfo info) { if (string.IsNullOrEmpty(path)) { info.ReportClientError("No path parameter was found"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(info.Request.QueryString["onlyfolders"].Value, false); bool showHidden = Library.Utility.Utility.ParseBool(info.Request.QueryString["showhidden"].Value, false); string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { info.ReportClientError("The path parameter must start with a forward-slash"); return; } if (!string.IsNullOrWhiteSpace(command)) { if ("validate".Equals(command, StringComparison.InvariantCultureIgnoreCase)) { try { if (System.IO.Path.IsPathRooted(path) && (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))) { info.OutputOK(); return; } } catch { } info.ReportServerError("File or folder not found"); return; } else { info.ReportClientError(string.Format("No such operation found: {0}", command)); return; } } try { if (path != "" && path != "/") { path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); } IEnumerable <Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = from di in System.IO.DriveInfo.GetDrives() where di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable select new Serializable.TreeNode() { id = di.RootDirectory.FullName, text = ( string.IsNullOrWhiteSpace(di.VolumeLabel) ? di.RootDirectory.FullName.Replace('\\', ' ') : di.VolumeLabel + " - " + di.RootDirectory.FullName.Replace('\\', ' ') ) + "(" + di.DriveType + ")", iconCls = "x-tree-icon-drive" }; } else { res = ListFolderAsNodes(path, skipFiles, showHidden); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = res.Select(x => { x.resolvedpath = x.id; x.id = specialtoken + x.id.Substring(specialpath.Length); return(x); }); } info.OutputOK(res); } catch (Exception ex) { info.ReportClientError("Failed to process the path: " + ex.Message); } }
private void GetFolderContents(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw) { HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString; if (input["path"] == null || input["path"].Value == null) { ReportError(response, bw, "The path parameter was not set"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(input["onlyfolders"].Value, false); var path = input["path"].Value; string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { ReportError(response, bw, "The path parameter must start with a forward-slash"); return; } try { if (path != "" && path != "/") { path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); } IEnumerable <Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = from di in System.IO.DriveInfo.GetDrives() where di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable select new Serializable.TreeNode() { id = di.RootDirectory.FullName, text = di.RootDirectory.FullName.Replace('\\', ' ') + "(" + di.DriveType + ")", iconCls = "x-tree-icon-drive" }; } else { res = ListFolderAsNodes(path, skipFiles); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = from n in res select new Serializable.TreeNode() { id = specialtoken + n.id.Substring(specialpath.Length), text = n.text, iconCls = n.iconCls, leaf = n.leaf, resolvedpath = n.id }; } bw.OutputOK(res); } catch (Exception ex) { ReportError(response, bw, "Failed to process the path: " + ex.Message); } }