public bool HasChild(string path, bool force, bool literalPath) { var runtime = new ProviderRuntime(SessionState, force, literalPath); var res = HasChild(path, runtime); runtime.ThrowFirstErrorOrContinue(); return res; }
public bool Exists(string path, bool force, bool literalPath) { var runtime = new ProviderRuntime(SessionState, force, literalPath); bool result = Exists(path, runtime); runtime.ThrowFirstErrorOrContinue(); return result; }
public Collection<PSObject> Copy(string[] path, string destinationPath, bool recurse, CopyContainers copyContainers, bool force, bool literalPath) { var runtime = new ProviderRuntime(SessionState, force, literalPath); Copy(path, destinationPath, recurse, copyContainers, runtime); return runtime.ThrowFirstErrorOrReturnResults(); }
public Collection<PathInfo> GetResolvedPSPathFromPSPath(string path) { var runtime = new ProviderRuntime(_sessionState); var res = GetResolvedPSPathFromPSPath(new [] { path }, runtime); runtime.ThrowFirstErrorOrContinue(); return res; }
internal Collection <PSObject> GetChildItems(string path, bool recurse, ProviderRuntime providerRuntime) { if (string.IsNullOrEmpty(path)) { path = CurrentLocation.Path; } CmdletProvider provider = GetProviderByPath(path); if ((path != null) && (ItemExists(provider, path, providerRuntime))) { if (IsItemContainer(provider, path, providerRuntime)) { ContainerCmdletProvider containerProvider = provider as ContainerCmdletProvider; if (containerProvider != null) { containerProvider.GetChildItems(path, recurse, providerRuntime); } } else { ItemCmdletProvider itemProvider = provider as ItemCmdletProvider; if (itemProvider != null) { itemProvider.GetItem(path, providerRuntime); } } } return(providerRuntime.RetreiveAllProviderData()); }
public Collection<string> GetNames(string[] path, ReturnContainers returnContainers, bool recurse, bool force, bool literalPath) { var runtime = new ProviderRuntime(SessionState, force, literalPath); GetNames(path, returnContainers, recurse, runtime); var packedResults = runtime.ThrowFirstErrorOrReturnResults(); var results = (from r in packedResults select r.ToString()).ToList(); return new Collection<string>(results); }
Collection <string> BuiltInGlobbing(CmdletProvider provider, string path, ProviderRuntime runtime) { var containerProvider = CmdletProvider.As <ContainerCmdletProvider>(provider); var ciIntrinsics = new ChildItemCmdletProviderIntrinsics(_sessionState); // first we split the path into globbable components and put them on a stack to work with var componentStack = PathToStack(containerProvider, path, runtime); // we create a working list with partially globbed paths. each iteration will take all items from the // list and add the newly globbed part var workingPaths = new List <string>() { "" }; while (componentStack.Count > 0) { var partialPaths = new List <string>(workingPaths); workingPaths.Clear(); var globComp = componentStack.Pop(); // check if the current stack component has wildcards. If not, simply append it to all partialPaths // and add to workingPaths if (!WildcardPattern.ContainsWildcardCharacters(globComp)) { workingPaths.AddRange(from p in partialPaths select Path.Combine(containerProvider, p, globComp, runtime)); continue; } // otherwise get all childnames, check wildcard and combine the paths var globWC = new WildcardPattern(globComp, WildcardOptions.IgnoreCase); foreach (var partPath in partialPaths) { if (!containerProvider.ItemExists(partPath, runtime) || !containerProvider.HasChildItems(partPath, runtime)) { // TODO: throw an error if there was no globbing already performed (then the first part of // the path already did not exists as in a pattern like "/home/notExisting/*.txt" continue; } // TODO: verify if we should only consider matching containers or all. maybe the filter won't // apply to partial parts and we need to consider all var childNames = ciIntrinsics.GetValidChildNames(containerProvider, partPath, ReturnContainers.ReturnMatchingContainers, runtime); // TODO: check if Include/Exclude also match partial parts, but i guess only complete ones // add all combined path to the workingPaths for the next stack globbing iteration workingPaths.AddRange(from c in childNames where globWC.IsMatch(c) select Path.Combine(containerProvider, partPath, c, runtime)); } } // now filter the working paths by include/exlude. last flag is false or we wouldn't be globbing var filter = new IncludeExcludeFilter(runtime.Include, runtime.Exclude, false); var globbedPaths = from p in workingPaths where filter.Accepts(p) select p; return(new Collection <string>(globbedPaths.ToList())); }
string GetProviderPathFromDriveQualifiedPath(string path, ProviderRuntime runtime, out ProviderInfo providerInfo, out PSDriveInfo drive) { var idx = path.IndexOf(":"); var driveName = path.Substring(0, idx); // TODO: validate drive name? drive = _sessionState.Drive.Get(driveName); providerInfo = drive.Provider; path = path.Substring(idx + 1).TrimStart(PathIntrinsics.CorrectSlash, PathIntrinsics.WrongSlash); return(Path.Combine(providerInfo.CreateInstance(), drive.Root, path, runtime)); }
private bool ItemExists(CmdletProvider provider, string path, ProviderRuntime providerRuntime) { ItemCmdletProvider itemProvider = provider as ItemCmdletProvider; if (itemProvider == null) { return(false); } return(itemProvider.ItemExists(path, providerRuntime)); }
private bool IsItemContainer(CmdletProvider provider, string path, ProviderRuntime providerRuntime) { NavigationCmdletProvider navigationProvider = provider as NavigationCmdletProvider; if (navigationProvider == null) { return(false); } return(navigationProvider.IsItemContainer(path, providerRuntime)); }
private string ResolveRelativePath(string path, ProviderRuntime runtime, ProviderInfo providerInfo) { var provider = _sessionState.Provider.GetInstance(providerInfo) as ContainerCmdletProvider; // TODO: I think PS default relative path resolving can only work with // paths that have slash/backslash as spearator. Verify this. // skip resolving if the path is absolute or we don't have a navigation provider var curRoot = runtime.PSDriveInfo.Root; if (provider == null || (curRoot.Length > 0 && path.StartsWith(curRoot))) { return(path); } if (IsCommonRootPath(path)) { return(Path.Combine(provider, curRoot, path, runtime)); } var curPath = runtime.PSDriveInfo.CurrentLocation; // we must stay in the same drive. to avoid to resolve to directories outside the drive, we first need to // get the path relative to the current drive's root // Example: the current drive's root is "/foo", the current location is "/foo/bar". If we resolve "../.." // we need to end up with "/foo", not "/", because "/" is outside the current drive // I hope this is just fine... at least PS doesn't call the provider NormalizeRelativePath method // for it. If we are in the current location, the path should also start with the drive's root, or // we are in some inconsistent state if (curPath.StartsWith(curRoot)) { curPath = curPath.Substring(curRoot.Length); } var relStack = PathToStack(provider, path, runtime); while (relStack.Count > 0) { var comp = relStack.Pop(); if (comp.Equals(".")) { continue; } else if (comp.Equals("..")) { curPath = Path.ParseParent(provider, curPath, "", runtime); continue; } // otherwise it's a child component to append curPath = Path.Combine(provider, curPath, comp, runtime); } // don't forget to append the root again return(Path.Combine(provider, curRoot, curPath, runtime)); }
// actual work with callid the providers internal void Get(string[] paths, bool recurse, ProviderRuntime runtime) { // the include/exclude filters apply to the results, not to the globbing process. Make this sure runtime.IgnoreFiltersForGlobbing = true; // globbing is here a little more complicated, so we do it "manually" (without GlobAndInvoke) foreach (var curPath in paths) { var path = curPath; // if the path won't be globbed or filtered, we will directly list it's child var listChildsWithoutRecursion = !Globber.ShouldGlob(path, runtime) && !runtime.HasFilters(); // the Path might be a mixture of a path and an include filter bool clearIncludeFilter; path = SplitFilterFromPath(path, recurse, runtime, out clearIncludeFilter); // now perform the actual globbing CmdletProvider provider; var globbed = Globber.GetGlobbedProviderPaths(path, runtime, out provider); var containerProvider = CmdletProvider.As<ContainerCmdletProvider>(provider); var filter = new IncludeExcludeFilter(runtime.Include, runtime.Exclude, false); foreach (var globPath in globbed) { try { // if we need to actively filter that stuff, we have to handle the recursion manually if (!filter.CanBeIgnored) { ManuallyGetChildItems(containerProvider, globPath, recurse, filter, runtime); return; } // otherwise just get the child items / the item directly if (recurse || listChildsWithoutRecursion) { GetItemOrChildItems(containerProvider, globPath, recurse, runtime); return; } // no recursion and globbing was performed: get the item, not the child items containerProvider.GetItem(globPath, runtime); } catch (Exception e) { HandleCmdletProviderInvocationException(e); } } // clean up the include filter of the runtime for the next item, if we split a filter from the path if (clearIncludeFilter) { runtime.Include.Clear(); } } }
public ProviderRuntime(ProviderRuntime runtime) : this(runtime.SessionState, runtime.Force, runtime.AvoidGlobbing) { _cmdlet = runtime._cmdlet; PassThru = runtime.PassThru; PSDriveInfo = runtime.PSDriveInfo; Include = new Collection<string>(runtime.Include); Exclude = new Collection<string>(runtime.Exclude); Filter = runtime.Filter; AvoidGlobbing = runtime.AvoidGlobbing; IgnoreFiltersForGlobbing = runtime.IgnoreFiltersForGlobbing; Credential = new PSCredential(runtime.Credential); DynamicParameters = runtime.DynamicParameters; }
public ProviderRuntime(ProviderRuntime runtime) : this(runtime.SessionState, runtime.Force, runtime.AvoidGlobbing) { _cmdlet = runtime._cmdlet; PassThru = runtime.PassThru; PSDriveInfo = runtime.PSDriveInfo; Include = new Collection <string>(runtime.Include); Exclude = new Collection <string>(runtime.Exclude); Filter = runtime.Filter; AvoidGlobbing = runtime.AvoidGlobbing; IgnoreFiltersForGlobbing = runtime.IgnoreFiltersForGlobbing; Credential = new PSCredential(runtime.Credential); DynamicParameters = runtime.DynamicParameters; }
public Collection<PSObject> New(string[] paths, string name, string itemTypeName, object content, bool force) { // TODO: support globbing (e.g. * in filename) Path normalizedPath; var runtime = new ProviderRuntime(_cmdlet.ExecutionContext); runtime.Force = force; foreach (var path in paths) { var provider = GetContainerProviderByPath(path, name, out normalizedPath); provider.NewItem(normalizedPath, itemTypeName, content, runtime); } runtime.ThrowFirstErrorOrContinue(); return runtime.RetreiveAllProviderData(); }
private string ResolveHomePath(string path, ProviderRuntime runtime, ProviderInfo providerInfo) { if (!IsHomePath(path) || providerInfo.Home == null) { return(path); } var provider = _sessionState.Provider.GetInstance(providerInfo); var restPath = path.Substring(1); var homePath = providerInfo.Home; // if the path is only something like '~/', PS will return only the Home, without trailing separator // But if it's '~/foo/', the trailing separator stays if (restPath.Length == 0 || restPath.Equals("/") || restPath.Equals("\\")) { return(homePath); } return(Path.Combine(provider, homePath, restPath, runtime)); }
internal Collection<string> GetGlobbedProviderPaths(string path, ProviderRuntime runtime, bool itemMustExist, out CmdletProvider provider) { var results = new Collection<string>(); ProviderInfo providerInfo; // get internal path, resolve home path and set provider info and drive info (if resolved) path = GetProviderSpecificPath(path, runtime, out providerInfo); provider = _sessionState.Provider.GetInstance(providerInfo); if (!ShouldGlob(path, runtime)) { // Although even ItemCmdletProvider supports ItemExists, PS doesn't seem // to throw errors when resolving paths with ItemProviders, only for ContainerProviders or higher // this behavior can be seen in the tests var containerProvider = provider as ContainerCmdletProvider; if (itemMustExist && containerProvider != null && !containerProvider.ItemExists(path, runtime)) { var msg = String.Format("An item with path {0} doesn't exist", path); runtime.WriteError(new ItemNotFoundException(msg).ErrorRecord); return results; } results.Add(path); return results; } if (providerInfo.Capabilities.HasFlag(ProviderCapabilities.ExpandWildcards)) { var filter = new IncludeExcludeFilter(runtime.Include, runtime.Exclude, runtime.IgnoreFiltersForGlobbing); foreach (var expanded in CmdletProvider.As<ItemCmdletProvider>(provider).ExpandPath(path, runtime)) { if (filter.Accepts(expanded)) { results.Add(expanded); } } } else { results = BuiltInGlobbing(provider, path, runtime); } return results; }
internal Collection <string> GetGlobbedProviderPaths(string path, ProviderRuntime runtime, bool itemMustExist, out CmdletProvider provider) { var results = new Collection <string>(); ProviderInfo providerInfo; // get internal path, resolve home path and set provider info and drive info (if resolved) path = GetProviderSpecificPath(path, runtime, out providerInfo); provider = _sessionState.Provider.GetInstance(providerInfo); if (!ShouldGlob(path, runtime)) { // Although even ItemCmdletProvider supports ItemExists, PS doesn't seem // to throw errors when resolving paths with ItemProviders, only for ContainerProviders or higher // this behavior can be seen in the tests var containerProvider = provider as ContainerCmdletProvider; if (itemMustExist && containerProvider != null && !containerProvider.ItemExists(path, runtime)) { var msg = String.Format("An item with path {0} doesn't exist", path); runtime.WriteError(new ItemNotFoundException(msg).ErrorRecord); return(results); } results.Add(path); return(results); } if (providerInfo.Capabilities.HasFlag(ProviderCapabilities.ExpandWildcards)) { var filter = new IncludeExcludeFilter(runtime.Include, runtime.Exclude, runtime.IgnoreFiltersForGlobbing); foreach (var expanded in CmdletProvider.As <ItemCmdletProvider>(provider).ExpandPath(path, runtime)) { if (filter.Accepts(expanded)) { results.Add(expanded); } } } else { results = BuiltInGlobbing(provider, path, runtime); } return(results); }
internal PathInfo SetLocation(string path, ProviderRuntime providerRuntime) { // TODO: deal with paths starting with ".\" if (path == null) { throw new NullReferenceException("Path can't be null"); } path = PathIntrinsics.NormalizePath(path); ProviderInfo provider = null; string driveName = null; string str = path; string providerId = null; PSDriveInfo currentDrive = CurrentDrive; // If path doesn't start with a drive name if (path.StartsWith(PathIntrinsics.CorrectSlash.ToString())) { provider = CurrentLocation.Provider; } else if (PathIntrinsics.IsAbsolutePath(path, out driveName)) { _currentDrive = GetDrive(driveName, null); path = PathIntrinsics.NormalizePath(PathIntrinsics.RemoveDriveName(path)); } _currentDrive.CurrentLocation = path; _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive; SetVariable("PWD", CurrentLocation); return(CurrentLocation); PSDriveInfo drive = CurrentDrive; SetLocation(path); }
internal string GetProviderSpecificPath(string path, ProviderRuntime runtime, out ProviderInfo providerInfo) { // differentiate between drive-qualified, provider-qualified, provider-internal, and provider-direct paths // then strip provider prefix, set provider, set drive is possible or get from Drive.Current PSDriveInfo drive; string resolvedPath = null; if (IsProviderQualifiedPath(path)) { resolvedPath = GetProviderPathFromProviderQualifiedPath(path, out providerInfo); // in case there is no CurrentDrive, set a dummy drive to keep track of the used provider drive = providerInfo.CurrentDrive ?? providerInfo.DummyDrive; } else if (IsDriveQualifiedPath(path)) { resolvedPath = GetProviderPathFromDriveQualifiedPath(path, runtime, out providerInfo, out drive); } // otherwise we first need to know about the provider/drive in use to properly resolve the path else if (runtime.PSDriveInfo != null) { drive = runtime.PSDriveInfo; providerInfo = drive.Provider; } else { drive = _sessionState.Path.CurrentLocation.Drive; providerInfo = _sessionState.Path.CurrentLocation.Provider; } // TODO: check for provider internal path beginning with \\ or // // make sure to set the drive to a dummy drive then runtime.PSDriveInfo = drive; // if we had no success, yet, we deal with some kind of provider specific (maybe relative) path if (resolvedPath == null) { resolvedPath = ResolveHomePath(path, runtime, providerInfo); resolvedPath = ResolveRelativePath(resolvedPath, runtime, providerInfo); } return(resolvedPath); }
internal string GetProviderSpecificPath(string path, ProviderRuntime runtime, out ProviderInfo providerInfo) { // differentiate between drive-qualified, provider-qualified, provider-internal, and provider-direct paths // then strip provider prefix, set provider, set drive is possible or get from Drive.Current PSDriveInfo drive; string resolvedPath = null; if (IsProviderQualifiedPath(path)) { resolvedPath = GetProviderPathFromProviderQualifiedPath(path, out providerInfo); // in case there is no CurrentDrive, set a dummy drive to keep track of the used provider drive = providerInfo.CurrentDrive ?? providerInfo.DummyDrive; } else if (IsDriveQualifiedPath(path)) { resolvedPath = GetProviderPathFromDriveQualifiedPath(path, runtime, out providerInfo, out drive); } // otherwise we first need to know about the provider/drive in use to properly resolve the path else if (runtime.PSDriveInfo != null) { drive = runtime.PSDriveInfo; providerInfo = drive.Provider; } else { drive = _sessionState.Path.CurrentLocation.Drive; providerInfo = _sessionState.Path.CurrentLocation.Provider; } // TODO: check for provider internal path beginning with \\ or // // make sure to set the drive to a dummy drive then runtime.PSDriveInfo = drive; // if we had no success, yet, we deal with some kind of provider specific (maybe relative) path if (resolvedPath == null) { resolvedPath = ResolveHomePath(path, runtime, providerInfo); resolvedPath = ResolveRelativePath(resolvedPath, runtime, providerInfo); } return resolvedPath; }
internal CmdletProvider Add(ProviderInfo providerInfo, ExecutionContext executionContext) { CmdletProvider provider = providerInfo.CreateInstance(); var runtime = new ProviderRuntime(executionContext.SessionState); providerInfo = provider.Start(providerInfo, runtime); provider.SetProviderInfo(providerInfo); // Cache the Provider's Info and instance if (!_providers.ContainsKey(providerInfo.Name)) { _providers.Add(providerInfo.Name, new List<ProviderInfo>()); } _providers[providerInfo.Name].Add(providerInfo); _providerInstances[providerInfo] = provider; // provider is added, default drives can be added AddDefaultDrives(provider, runtime); return provider; }
void SetPathTypes(string path, SessionState sessionState) { ProviderInfo pinfo; // use the globber to parse the path and set the different types var runtime = new ProviderRuntime(sessionState); runtime.PSDriveInfo = Drive; var globber = new PathGlobber(sessionState); _path = globber.GetProviderSpecificPath(path, runtime, out pinfo); // update the Provider and Drive in case it changed Provider = pinfo; Drive = runtime.PSDriveInfo; _providerQualified = globber.GetProviderQualifiedPath(_path, Provider); Path = _providerQualified; if (Drive != null && !String.IsNullOrEmpty(Drive.Name)) { _driveQualified = globber.GetDriveQualifiedPath(_path, Drive); Path = _driveQualified; } }
internal Collection<string> GetChildNames(string path, ReturnContainers returnContainers, bool recurse, ProviderRuntime providerRuntime) { // MUST: fix throw new NotImplementedException(); }
internal PathInfo SetLocation(string path, ProviderRuntime providerRuntime) { // TODO: deal with paths starting with ".\" if (path == null) { throw new NullReferenceException("Path can't be null"); } path = PathIntrinsics.NormalizePath(path); ProviderInfo provider = null; string driveName = null; string str = path; PSDriveInfo currentDrive = CurrentDrive; // If path doesn't start with a drive name if (path.StartsWith(PathIntrinsics.CorrectSlash.ToString())) { provider = CurrentLocation.Provider; } else if (PathIntrinsics.IsAbsolutePath(path, out driveName)) { _currentDrive = GetDrive(driveName, null); path = PathIntrinsics.NormalizePath(PathIntrinsics.RemoveDriveName(path)); } _currentDrive.CurrentLocation = path; _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive; SetVariable("PWD", CurrentLocation); return CurrentLocation; }
internal PathInfo SetLocation(Path path, ProviderRuntime providerRuntime) { // TODO: deal with paths starting with ".\" if (path == null) { throw new NullReferenceException("Path can't be null"); } PSDriveInfo nextDrive = CurrentDrive; path = path.NormalizeSlashes().ResolveTilde(); string driveName = null; if (path.TryGetDriveName(out driveName)) { try { nextDrive = _executionContext.SessionState.Drive.Get(driveName); } catch (MethodInvocationException) //didn't find a drive (maybe it's "\" on Windows) { nextDrive = CurrentDrive; } } Path newLocation = PathNavigation.CalculateFullPath(nextDrive.CurrentLocation, path); // I'm not a fan of this block of code. // The goal here is to throw an exception if trying to "CD" into an invalid location // // Not sure why the providerInstances are returned as a collection. Feels like given a // path we should have one provider we're talking to. if (_providerInstances.ContainsKey(nextDrive.Provider.Name)) { bool pathExists = false; IEnumerable <ItemCmdletProvider> cmdletProviders = _providerInstances[nextDrive.Provider.Name].Where(x => x is ItemCmdletProvider).Cast <ItemCmdletProvider>(); ItemCmdletProvider currentProvider = null; foreach (var provider in cmdletProviders) { if (provider.ItemExists(newLocation, providerRuntime)) { pathExists = true; currentProvider = provider; break; } } if (!pathExists) { throw new Exception(string.Format("Cannot find path '{0}' because it does not exist.", newLocation)); } else { if (currentProvider is FileSystemProvider) { System.Environment.CurrentDirectory = newLocation; } } } else { throw new NotImplementedException("Unsure how to set location with provider:" + nextDrive.Provider.Name); } nextDrive.CurrentLocation = newLocation; CurrentDrive = nextDrive; _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive; return(CurrentLocation); }
internal Collection<PSObject> GetChildItems(string path, bool recurse, ProviderRuntime providerRuntime) { if (string.IsNullOrEmpty(path)) path = CurrentLocation.Path; CmdletProvider provider = GetProviderByPath(path); if ((path != null) && (ItemExists(provider, path, providerRuntime))) { if (IsItemContainer(provider, path, providerRuntime)) { ContainerCmdletProvider containerProvider = provider as ContainerCmdletProvider; if (containerProvider != null) containerProvider.GetChildItems(path, recurse, providerRuntime); } else { ItemCmdletProvider itemProvider = provider as ItemCmdletProvider; if (itemProvider != null) itemProvider.GetItem(path, providerRuntime); } } return providerRuntime.RetreiveAllProviderData(); }
//internal object GetChildItemsDynamicParameters(Path path, bool recurse, CmdletProviderContext context); internal void GetChildNames(Path path, ReturnContainers returnContainers, ProviderRuntime runtime) { ProviderRuntime = runtime; GetChildNames(path, returnContainers); }
internal void NewItem(Path path, string type, object newItemValue, ProviderRuntime runtime) { ProviderRuntime = runtime; NewItem(path, type, newItemValue); }
internal Collection <string> GetGlobbedProviderPaths(string path, ProviderRuntime runtime, out CmdletProvider provider) { return(GetGlobbedProviderPaths(path, runtime, true, out provider)); }
// internals internal void CopyItem(Path path, Path copyPath, bool recurse, ProviderRuntime runtime) { ProviderRuntime = runtime; CopyItem(path, copyPath, recurse); }
internal bool ShouldGlob(string path, ProviderRuntime runtime) { return(WildcardPattern.ContainsWildcardCharacters(path) && !runtime.AvoidGlobbing.IsPresent); }
private Stack <string> PathToStack(ContainerCmdletProvider provider, string path, ProviderRuntime runtime) { var componentStack = new Stack <string>(); while (!String.IsNullOrEmpty(path)) { var child = Path.ParseChildName(provider, path, runtime); componentStack.Push(child); var parentPath = Path.ParseParent(provider, path, "", runtime); if (parentPath.Equals(path)) { throw new PSInvalidOperationException("Provider's implementation of GetParentPath is inconsistent", "ParentOfPathIsPath", ErrorCategory.InvalidResult); } path = parentPath; } return(componentStack); }
internal Collection <PSObject> GetChildItems(string path, bool recurse) { ProviderRuntime providerRuntime = new ProviderRuntime(_executionContext); return(GetChildItems(path, recurse, providerRuntime)); }
public bool IsContainer(string path) { var runtime = new ProviderRuntime(SessionState); bool result = IsContainer(path, runtime); runtime.ThrowFirstErrorOrContinue(); return result; }
public void Invoke(string[] path, bool literalPath) { var runtime = new ProviderRuntime(SessionState); runtime.AvoidGlobbing = literalPath; Invoke(path, runtime); runtime.ThrowFirstErrorOrContinue(); }
private bool IsItemContainer(CmdletProvider provider, string path, ProviderRuntime providerRuntime) { NavigationCmdletProvider navigationProvider = provider as NavigationCmdletProvider; if (navigationProvider == null) return false; return navigationProvider.IsItemContainer(path, providerRuntime); }
internal Collection <string> GetChildNames(string path, ReturnContainers returnContainers, bool recurse, ProviderRuntime providerRuntime) { // MUST: fix throw new NotImplementedException(); }
private bool ItemExists(CmdletProvider provider, string path, ProviderRuntime providerRuntime) { ItemCmdletProvider itemProvider = provider as ItemCmdletProvider; if (itemProvider == null) return false; return itemProvider.ItemExists(path, providerRuntime); }
internal PathInfo SetLocation(Path path, ProviderRuntime providerRuntime) { // TODO: deal with paths starting with ".\" if (path == null) { throw new NullReferenceException("Path can't be null"); } if (path == "~") { // Older Mono versions (sadly the one that's currently still // available) have a bug where GetFolderPath returns an empty // string for most SpecialFolder values, but only on // non-Windows. // See: https://bugzilla.xamarin.com/show_bug.cgi?id=2873 path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); // HACK: Use $Env:HOME until Mono 2.10 dies out. if (path == "") { path = Environment.GetEnvironmentVariable("HOME"); } } PSDriveInfo nextDrive = CurrentDrive; path = path.NormalizeSlashes(); string driveName = null; if (path.TryGetDriveName(out driveName)) { nextDrive = GetDrive(driveName); } if (nextDrive == null) { nextDrive = CurrentDrive; } Path newLocation = PathNavigation.CalculateFullPath(nextDrive.CurrentLocation, path); // I'm not a fan of this block of code. // The goal here is to throw an exception if trying to "CD" into an invalid location // // Not sure why the providerInstances are returned as a collection. Feels like given a // path we should have one provider we're talking to. if (_providerInstances.ContainsKey(nextDrive.Provider.Name)) { bool pathExists = false; IEnumerable <ItemCmdletProvider> cmdletProviders = _providerInstances[nextDrive.Provider.Name].Where(x => x is ItemCmdletProvider).Cast <ItemCmdletProvider>(); ItemCmdletProvider currentProvider = null; foreach (var provider in cmdletProviders) { if (provider.ItemExists(newLocation, providerRuntime)) { pathExists = true; currentProvider = provider; break; } } if (!pathExists) { throw new Exception(string.Format("Cannot find path '{0}' because it does not exist.", newLocation)); } else { if (currentProvider is FileSystemProvider) { System.Environment.CurrentDirectory = newLocation; } } } else { throw new NotImplementedException("Unsure how to set location with provider:" + nextDrive.Provider.Name); } nextDrive.CurrentLocation = newLocation; CurrentDrive = nextDrive; _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive; return(CurrentLocation); }
//internal object CopyItemDynamicParameters(Path path, Path destination, bool recurse, CmdletProviderContext context); internal void GetChildItems(Path path, bool recurse, ProviderRuntime runtime) { ProviderRuntime = runtime; GetChildItems(path, recurse); }
internal PathInfo SetLocation(Path path, ProviderRuntime providerRuntime) { // TODO: deal with paths starting with ".\" if (path == null) { throw new NullReferenceException("Path can't be null"); } if (path == "~") { // Older Mono versions (sadly the one that's currently still // available) have a bug where GetFolderPath returns an empty // string for most SpecialFolder values, but only on // non-Windows. // See: https://bugzilla.xamarin.com/show_bug.cgi?id=2873 path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); // HACK: Use $Env:HOME until Mono 2.10 dies out. if (path == "") path = Environment.GetEnvironmentVariable("HOME"); } PSDriveInfo nextDrive = CurrentDrive; path = path.NormalizeSlashes(); string driveName = null; if (path.TryGetDriveName(out driveName)) { try { nextDrive = _executionContext.SessionState.Drive.Get(driveName); } catch (MethodInvocationException) //didn't find a drive (maybe it's "\" on Windows) { nextDrive = CurrentDrive; } } Path newLocation = PathNavigation.CalculateFullPath(nextDrive.CurrentLocation, path); // I'm not a fan of this block of code. // The goal here is to throw an exception if trying to "CD" into an invalid location // // Not sure why the providerInstances are returned as a collection. Feels like given a // path we should have one provider we're talking to. if (_providerInstances.ContainsKey(nextDrive.Provider.Name)) { bool pathExists = false; IEnumerable<ItemCmdletProvider> cmdletProviders = _providerInstances[nextDrive.Provider.Name].Where(x => x is ItemCmdletProvider).Cast<ItemCmdletProvider>(); ItemCmdletProvider currentProvider = null; foreach (var provider in cmdletProviders) { if (provider.ItemExists(newLocation, providerRuntime)) { pathExists = true; currentProvider = provider; break; } } if (!pathExists) { throw new Exception(string.Format("Cannot find path '{0}' because it does not exist.", newLocation)); } else { if (currentProvider is FileSystemProvider) { System.Environment.CurrentDirectory = newLocation; } } } else { throw new NotImplementedException("Unsure how to set location with provider:" + nextDrive.Provider.Name); } nextDrive.CurrentLocation = newLocation; CurrentDrive = nextDrive; _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive; return CurrentLocation; }
//internal object GetChildNamesDynamicParameters(Path path, CmdletProviderContext context); internal bool HasChildItems(Path path, ProviderRuntime runtime) { ProviderRuntime = runtime; return HasChildItems(path); }
internal Collection<PSObject> GetChildItems(string path, bool recurse) { ProviderRuntime providerRuntime = new ProviderRuntime(_executionContext); return GetChildItems(path, recurse, providerRuntime); }
//internal object NewItemDynamicParameters(Path path, Path type, object newItemValue, CmdletProviderContext context); internal void RemoveItem(Path path, bool recurse, ProviderRuntime runtime) { ProviderRuntime = runtime; RemoveItem(path, recurse); }
//internal object RemoveItemDynamicParameters(Path path, bool recurse, CmdletProviderContext context); internal void RenameItem(Path path, string newName, ProviderRuntime runtime) { ProviderRuntime = runtime; RenameItem(path, newName); }
internal ProviderInfo Start(ProviderInfo providerInfo, ProviderRuntime providerRuntime) { ProviderRuntime = providerRuntime; return Start(providerInfo); }
public Collection<PSObject> Get(string[] path, bool force, bool literalPath) { var runtime = new ProviderRuntime(SessionState, force, literalPath); Get(path, runtime); return runtime.ThrowFirstErrorOrReturnResults(); }