Example #1
0
 public Context(CmdletProvider provider, string path, PSDriveInfo drive, IPathNodeProcessor pathProcessor, object dynamicParameters, Version topology, bool recurse)
 {
     _pathProcessor = pathProcessor;
     DynamicParameters = dynamicParameters;
     _provider = provider;
     _path = path;
     _drive = drive;
     _recurse = recurse;
     PathTopologyVersion = topology;
 }
Example #2
0
 public ProviderContext(CmdletProvider provider, string path, PSDriveInfo drive, IPathResolver pathProcessor, object dynamicParameters, Version topology, bool recurse)
 {
     this.pathProcessor = pathProcessor;
     DynamicParameters = dynamicParameters;
     this.provider = provider;
     this.path = path;
     this.drive = drive;
     this.recurse = recurse;
     PathTopologyVersion = topology;
 }
        public Context( IContext context, object dynamicParameters )
        {
            Context c = context as Context;
            if( null == c )
            {
                throw new ArgumentException( "the context provided is of an incompatible type");
            }

            _provider = c._provider;
            PathProcessor = c.PathProcessor;
            DynamicParameters = dynamicParameters;
        }
        protected ItemContentReaderWriterBase(CmdletProvider provider, Item item,
            FileSystemCmdletProviderEncoding encoding, bool raw)
        {
            Item = item;
            Provider = provider;
            Raw = raw;

            if (encoding == FileSystemCmdletProviderEncoding.Unknown)
            {
                encoding = FileSystemCmdletProviderEncoding.Byte;
            }
            Encoding = new FileSystemContentWriterDynamicParameters() {Encoding = encoding}.EncodingType;
        }
Example #5
0
        public Context( IContext context, object dynamicParameters )
        {
            Context c = context as Context;
            if( null == c )
            {
                throw new ArgumentException( "the context provided is of an incompatible type");
            }

            _provider = c._provider;
            _drive = c._drive;
            _path = c._path;
            _pathProcessor = c._pathProcessor;
            DynamicParameters = dynamicParameters;
            _recurse = c.Recurse;
            PathTopologyVersion = c.PathTopologyVersion;
        }
Example #6
0
 public ItemContentWriter(CmdletProvider provider, Item item, string path,  FileSystemCmdletProviderEncoding encoding, string extension, bool raw, bool fileBased, bool versioned, string language)
     : base(provider, item, encoding, raw)
 {
     if (Encoding != null && !Raw)
     {
         encoder = Encoding.GetEncoder();
     }
     if (!string.IsNullOrEmpty(extension))
     {
         this.extension = extension.StartsWith(".") ? extension : "." + extension;
     }
     this.fileBased = fileBased;
     this.path = path;
     this.versioned = versioned;
     this.language = language ?? Item?.Language?.Name;
     database = Item?.Database?.Name ?? PathUtilities.GetDrive(path, "master");
 }
Example #7
0
        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;
        }
        /// <summary>
        /// Gets an instance of an ISecurityDescriptorCmdletProvider given the provider ID.
        /// </summary>
        /// 
        /// <param name="providerInstance">
        /// An instance of a CmdletProvider.
        /// </param>
        /// 
        /// <returns>
        /// An instance of a ISecurityDescriptorCmdletProvider for the specified provider ID.
        /// </returns>
        /// 
        /// <throws>
        /// ArgumentNullException if providerId is null.
        /// NotSupportedException if the providerId is not for a provider
        /// that is derived from ISecurityDescriptorCmdletProvider.
        /// </throws>
        /// 
        internal static ISecurityDescriptorCmdletProvider GetPermissionProviderInstance(CmdletProvider providerInstance)
        {
            if (providerInstance == null)
            {
                throw PSTraceSource.NewArgumentNullException("providerInstance");
            }

            ISecurityDescriptorCmdletProvider permissionCmdletProvider =
                providerInstance as ISecurityDescriptorCmdletProvider;

            if (permissionCmdletProvider == null)
            {
                throw
                    PSTraceSource.NewNotSupportedException(
                        ProviderBaseSecurity.ISecurityDescriptorCmdletProvider_NotSupported);
            }

            return permissionCmdletProvider;
        } // GetPermissionProviderInstance
 public FileSystemContentReaderWriter(string path, string streamName, FileMode mode, FileAccess access, FileShare share, Encoding encoding, bool usingByteEncoding, bool waitForChanges, CmdletProvider provider, bool isRawStream)
 {
     this.delimiter = "\n";
     if (string.IsNullOrEmpty(path))
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     tracer.WriteLine("path = {0}", new object[] { path });
     tracer.WriteLine("mode = {0}", new object[] { mode });
     tracer.WriteLine("access = {0}", new object[] { access });
     this.path = path;
     this.streamName = streamName;
     this.mode = mode;
     this.access = access;
     this.share = share;
     this.encoding = encoding;
     this.usingByteEncoding = usingByteEncoding;
     this.waitForChanges = waitForChanges;
     this.provider = provider;
     this.isRawStream = isRawStream;
     this.CreateStreams(path, streamName, mode, access, share, encoding);
 }
Example #10
0
 public ProviderContext(CmdletProvider provider, string path, PSDriveInfo drive, IPathResolver pathProcessor, object dynamicParameters, Version topology)
     : this(provider, path, drive, pathProcessor, dynamicParameters, topology, false)
 {
 }
Example #11
0
 internal Collection<string> GetGlobbedProviderPathsFromMonadPath(string path, bool allowNonexistingPaths, CmdletProviderContext context, out ProviderInfo provider, out CmdletProvider providerInstance)
 {
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     if (context == null)
     {
         throw PSTraceSource.NewArgumentNullException("context");
     }
     using (pathResolutionTracer.TraceScope("Resolving MSH path \"{0}\" to PROVIDER-INTERNAL path", new object[] { path }))
     {
         TraceFilters(context);
         if (IsProviderQualifiedPath(path))
         {
             context.Drive = null;
         }
         PSDriveInfo drive = null;
         if (this.GetProviderPath(path, context, out provider, out drive) == null)
         {
             providerInstance = null;
             tracer.WriteLine("provider returned a null path so return an empty array", new object[0]);
             pathResolutionTracer.WriteLine("Provider '{0}' returned null", new object[] { provider });
             return new Collection<string>();
         }
         if (drive != null)
         {
             context.Drive = drive;
         }
         Collection<string> collection = new Collection<string>();
         foreach (PathInfo info2 in this.GetGlobbedMonadPathsFromMonadPath(path, allowNonexistingPaths, context, out providerInstance))
         {
             collection.Add(info2.ProviderPath);
         }
         return collection;
     }
 }
Example #12
0
 internal Collection<string> GetGlobbedProviderPathsFromMonadPath(string path, bool allowNonexistingPaths, out ProviderInfo provider, out CmdletProvider providerInstance)
 {
     providerInstance = null;
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.sessionState.Internal.ExecutionContext);
     return this.GetGlobbedProviderPathsFromMonadPath(path, allowNonexistingPaths, context, out provider, out providerInstance);
 }
Example #13
0
        internal Collection<PathInfo> GetGlobbedMonadPathsFromMonadPath (string path, bool allowNonexistingPaths, CmdletProviderContext context, out CmdletProvider providerInstance)
		{
			providerInstance = null;
			if (path == null) {
				throw PSTraceSource.NewArgumentNullException ("path");
			}
			if (context == null) {
				throw PSTraceSource.NewArgumentNullException ("context");
			}
            Collection<PathInfo> collection = new Collection<PathInfo>();
            using (pathResolutionTracer.TraceScope("Resolving MSH path \"{0}\" to MSH path", new object[] { path }))
            {
                TraceFilters(context);
                if (IsHomePath(path))
                {
                    using (pathResolutionTracer.TraceScope("Resolving HOME relative path.", new object[0]))
                    {
                        path = this.GetHomeRelativePath(path);
                    }
                }
                bool isProviderDirectPath = IsProviderDirectPath(path);
                bool isProviderQualifiedPath = IsProviderQualifiedPath(path);
                if (isProviderDirectPath || isProviderQualifiedPath)
                {
                    collection = this.ResolvePSPathFromProviderPath(path, context, allowNonexistingPaths, isProviderDirectPath, isProviderQualifiedPath, out providerInstance);
                }
                else
                {
                    collection = this.ResolveDriveQualifiedPath(path, context, allowNonexistingPaths, out providerInstance);
                }
                if (((allowNonexistingPaths || (collection.Count >= 1)) || WildcardPattern.ContainsWildcardCharacters(path)) || ((context.Include != null) && (context.Include.Count != 0)))
                {
                    return collection;
                }
                if ((context.Exclude != null) && (context.Exclude.Count != 0))
                {
                    return collection;
                }
                ItemNotFoundException exception = new ItemNotFoundException(path, "PathNotFound", SessionStateStrings.PathNotFound);
                pathResolutionTracer.TraceError("Item does not exist: {0}", new object[] { path });
                throw exception;
            }
        }
Example #14
0
 internal Collection<PathInfo> GetGlobbedMonadPathsFromMonadPath(string path, bool allowNonexistingPaths, out CmdletProvider providerInstance)
 {
     CmdletProviderContext context = new CmdletProviderContext(this.sessionState.Internal.ExecutionContext);
     return this.GetGlobbedMonadPathsFromMonadPath(path, allowNonexistingPaths, context, out providerInstance);
 }
Example #15
0
        internal string GetDriveRootRelativePathFromPSPath (string path, CmdletProviderContext context, bool escapeCurrentLocation, out PSDriveInfo workingDriveForPath, out CmdletProvider providerInstance)
		{
			if (path == null) {
				throw PSTraceSource.NewArgumentNullException ("path");
			}
			if (OSHelper.IsUnix) {
				int index = path.IndexOf ("::");
				if (index != -1)
				{
					path = path.Substring (index + 2);
				}
			}
            workingDriveForPath = null;
            string driveName = null;
            if (this.sessionState.Drive.Current != null)
            {
                driveName = this.sessionState.Drive.Current.Name;
            }
            bool flag = false;
            if (this.IsAbsolutePath(path, out driveName))
            {
                tracer.WriteLine("Drive Name: {0}", new object[] { driveName });
                try
                {
                    workingDriveForPath = this.sessionState.Drive.Get(driveName);
                }
                catch (DriveNotFoundException)
                {
                    if (this.sessionState.Drive.Current == null)
                    {
                        throw;
                    }
					if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix)
					{
						flag = path.StartsWith ("/", StringComparison.OrdinalIgnoreCase);
						workingDriveForPath = this.sessionState.Drive.Current;
					}
					else
					{
						string str2 = OSHelper.IsUnix ? this.sessionState.Drive.Current.Root : this.sessionState.Drive.Current.Root.Replace('/', '\\');
						string tempPath = OSHelper.IsUnix ? path : path.Replace('/', '\\');
	                    if ((str2.IndexOf(":", StringComparison.CurrentCulture) >= 0) && tempPath.StartsWith(str2, StringComparison.OrdinalIgnoreCase))
	                    {
	                        flag = true;
							if (!OSHelper.IsUnix) {
		                        path = path.Substring(str2.Length);
		                        path = path.TrimStart(new char[] { '\\' });
		                        path = '\\' + path;
							}
	                        workingDriveForPath = this.sessionState.Drive.Current;
	                    }
	                    if (!flag)
	                    {
	                        throw;
	                    }
					}
                }
				if (!flag) /* && !OSHelper.IsUnix */
                {
                    path = path.Substring(driveName.Length + 1);
                }
            }
            else
            {
                workingDriveForPath = this.sessionState.Drive.Current;
            }
            if (workingDriveForPath == null)
            {
                ItemNotFoundException exception = new ItemNotFoundException(path, "PathNotFound", SessionStateStrings.PathNotFound);
                pathResolutionTracer.TraceError("Item does not exist: {0}", new object[] { path });
                throw exception;
            }
            try
            {
                providerInstance = this.sessionState.Internal.GetContainerProviderInstance(workingDriveForPath.Provider);
                context.Drive = workingDriveForPath;
                return this.GenerateRelativePath(workingDriveForPath, path, escapeCurrentLocation, providerInstance, context);
            }
            catch (PSNotSupportedException)
            {
                providerInstance = null;
                return "";
            }
        }
Example #16
0
 /// <summary>
 /// Constructor for the content stream
 /// </summary>
 /// 
 /// <param name="path">
 /// The path to the file to get the content from.
 /// </param>
 /// 
 /// <param name="streamName">
 /// The name of the Alternate Data Stream to get the content from. If null or empty, returns
 /// the file's primary content.
 /// </param>
 /// 
 /// <param name="mode">
 /// The file mode to open the file with.
 /// </param>
 /// 
 /// <param name="access">
 /// The file access requested in the file.
 /// </param>
 /// 
 /// <param name="share">
 /// The file share to open the file with
 /// </param>
 ///
 /// <param name="encoding">
 /// The encoding of the file to be read or written.
 /// </param>
 /// 
 /// <param name="usingByteEncoding">
 /// If true, bytes will be read from the file. If false, the specified encoding
 /// will be used to read the file.
 /// </param>
 /// 
 /// <param name="waitForChanges">
 /// If true, we will perform blocking reads on the file, waiting for new content to be appended
 /// </param>
 /// 
 /// <param name="provider">
 /// The CmdletProvider invoking this stream
 /// </param>
 /// 
 /// <param name="isRawStream">
 /// Indicates raw stream.
 /// </param>
 /// 
 /// <param name="suppressNewline">
 /// False to add a newline to the end of the output string, true if not.
 /// </param>
 /// 
 public FileSystemContentReaderWriter(
     string path, string streamName, FileMode mode, FileAccess access, FileShare share,
     Encoding encoding, bool usingByteEncoding, bool waitForChanges, CmdletProvider provider,
     bool isRawStream, bool suppressNewline)
         : this(path, streamName, mode, access, share, encoding, usingByteEncoding, waitForChanges, provider, isRawStream)
 {
     _suppressNewline = suppressNewline;
 }
Example #17
0
        /// <summary>
        /// Creates an instance of the provider.
        /// </summary>
        /// <returns>
        /// An instance of the provider or null if one could not be created.
        /// </returns>
        /// <exception cref="ProviderNotFoundException">
        /// If an instance of the provider could not be created because the
        /// type could not be found in the assembly.
        /// </exception>
        internal Provider.CmdletProvider CreateInstance()
        {
            // It doesn't really seem that using thread local storage to store an
            // instance of the provider is really much of a performance gain and it
            // still causes problems with the CmdletProviderContext when piping two
            // commands together that use the same provider.
            // get-child -filter a*.txt | get-content
            // This pipeline causes problems when using a cached provider instance because
            // the CmdletProviderContext gets changed when get-content gets called.
            // When get-content finishes writing content from the first output of get-child
            // get-child gets control back and writes out a FileInfo but the WriteObject
            // from get-content gets used because the CmdletProviderContext is still from
            // that cmdlet.
            // Possible solutions are to not cache the provider instance, or to maintain
            // a CmdletProviderContext stack in ProviderBase.  Each method invocation pushes
            // the current context and the last action of the method pops back to the
            // previous context.
#if USE_TLS
            // Next see if we already have an instance in thread local storage

            object providerInstance = Thread.GetData(instance);

            if (providerInstance == null)
            {
#else
            object providerInstance = null;
#endif
            // Finally create an instance of the class
            Exception invocationException = null;

            try
            {
                providerInstance =
                    Activator.CreateInstance(this.ImplementingType);
            }
            catch (TargetInvocationException targetException)
            {
                invocationException = targetException.InnerException;
            }
            catch (MissingMethodException)
            {
            }
            catch (MemberAccessException)
            {
            }
            catch (ArgumentException)
            {
            }
#if USE_TLS
                // cache the instance in thread local storage

                Thread.SetData(instance, providerInstance);
            }
#endif

            if (providerInstance == null)
            {
                ProviderNotFoundException e = null;

                if (invocationException != null)
                {
                    e =
                        new ProviderNotFoundException(
                            this.Name,
                            SessionStateCategory.CmdletProvider,
                            "ProviderCtorException",
                            SessionStateStrings.ProviderCtorException,
                            invocationException.Message);
                }
                else
                {
                    e =
                        new ProviderNotFoundException(
                            this.Name,
                            SessionStateCategory.CmdletProvider,
                            "ProviderNotFoundInAssembly",
                            SessionStateStrings.ProviderNotFoundInAssembly);
                }

                throw e;
            }

            Provider.CmdletProvider result = providerInstance as Provider.CmdletProvider;

            Dbg.Diagnostics.Assert(
                result != null,
                "DiscoverProvider should verify that the class is derived from CmdletProvider so this is just validation of that");

            result.SetProviderInformation(this);
            return result;
        }
Example #18
0
        private bool IsItemContainer(CmdletProvider provider, string path, ProviderRuntime providerRuntime)
        {
            NavigationCmdletProvider navigationProvider = provider as NavigationCmdletProvider;

            if (navigationProvider == null)
                return false;

            return navigationProvider.IsItemContainer(path, providerRuntime);
        }
Example #19
0
        public ProviderContext(IProviderContext providerContext, object dynamicParameters)
        {
            ProviderContext c = providerContext as ProviderContext;
            if (null == c)
            {
                throw new ArgumentException("the providerContext provided is of an incompatible type");
            }

            provider = c.provider;
            drive = c.drive;
            path = c.path;
            pathProcessor = c.pathProcessor;
            DynamicParameters = dynamicParameters;
            recurse = c.Recurse;
            PathTopologyVersion = c.PathTopologyVersion;
        }
Example #20
0
 internal Collection<string> GetGlobbedProviderPathsFromProviderPath(string path, bool allowNonexistingPaths, string providerId, out CmdletProvider providerInstance)
 {
     providerInstance = null;
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     CmdletProviderContext context = new CmdletProviderContext(this.sessionState.Internal.ExecutionContext);
     Collection<string> collection = this.GetGlobbedProviderPathsFromProviderPath(path, allowNonexistingPaths, providerId, context, out providerInstance);
     if (context.HasErrors())
     {
         ErrorRecord record = context.GetAccumulatedErrorObjects()[0];
         if (record != null)
         {
             throw record.Exception;
         }
     }
     return collection;
 }
Example #21
0
 /// <summary>
 /// Constructor for the content stream
 /// </summary>
 /// 
 /// <param name="path">
 /// The path to the file to get the content from.
 /// </param>
 /// 
 /// <param name="streamName">
 /// The name of the Alternate Data Stream to get the content from. If null or empty, returns
 /// the file's primary content.
 /// </param>
 /// 
 /// <param name="mode">
 /// The file mode to open the file with.
 /// </param>
 /// 
 /// <param name="access">
 /// The file access requested in the file.
 /// </param>
 /// 
 ///  <param name="share">
 ///    The file share to open the file with
 ///  </param>
 /// 
 /// <param name="delimiter">
 /// The delimiter to use when reading strings. Each time read is called, all contents up to an including
 /// the delimiter is read.
 /// </param>
 /// 
 /// <param name="encoding">
 /// The encoding of the file to be read or written.
 /// </param>
 /// 
 /// <param name="waitForChanges">
 /// If true, we will perform blocking reads on the file, waiting for new content to be appended
 /// </param>
 /// 
 /// <param name="provider">
 /// The CmdletProvider invoking this stream
 /// </param>
 /// 
 /// <param name="isRawStream">
 /// Indicates raw stream.
 /// </param>
 /// 
 public FileSystemContentReaderWriter(
     string path,
     string streamName,
     FileMode mode,
     FileAccess access,
     FileShare share,
     string delimiter,
     Encoding encoding,
     bool waitForChanges,
     CmdletProvider provider,
     bool isRawStream)
     : this(path, streamName, mode, access, share, encoding, false, waitForChanges, provider, isRawStream)
 {
     _delimiter = delimiter;
     _usingDelimiter = true;
 }
Example #22
0
 public ProviderContext(CmdletProvider provider, string path, PSDriveInfo drive, IPathResolver pathProcessor, object dynamicParameters, bool recurse)
     : this(provider, path, drive, pathProcessor, dynamicParameters, new Version(1, 0), recurse)
 {
 }
Example #23
0
        internal string GenerateRelativePath(PSDriveInfo drive, string path, bool escapeCurrentLocation, CmdletProvider providerInstance, CmdletProviderContext context)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }
            if (drive == null)
            {
                throw PSTraceSource.NewArgumentNullException("drive");
            }
            string currentLocation = drive.CurrentLocation;
			bool flag1 = OSHelper.IsUnix && drive.Root.StartsWith ("/");
			if (!flag1 && !string.IsNullOrEmpty(currentLocation) && currentLocation.StartsWith(drive.Root, StringComparison.Ordinal))
            {
                currentLocation = currentLocation.Substring(drive.Root.Length);
            }
            if (escapeCurrentLocation)
            {
                currentLocation = WildcardPattern.Escape(currentLocation);
            }
            if (!string.IsNullOrEmpty(path))
            {
				var flag6 = OSHelper.IsUnix;
				var flag7 = flag6;
				if (!flag6) flag6 = (path[0] != '/');
                if ((path[0] != '\\') && flag6)
                {
                Label_024B:
                    if ((path.Length > 0) && this.HasRelativePathTokens(path))
                    {
                        if (context.Stopping)
                        {
                            throw new PipelineStoppedException();
                        }
                        bool flag = false;
                        bool flag2 = path.StartsWith("..", StringComparison.Ordinal);
                        bool flag3 = path.Length == 2;
                        bool flag4 = (path.Length > 2) && ((path[2] == '\\') || (path[2] == '/'));
						if (flag7) flag4 = flag7;
                        if (flag2 && (flag3 || flag4))
                        {
                            if (!string.IsNullOrEmpty(currentLocation))
                            {
                                currentLocation = this.sessionState.Internal.GetParentPath(providerInstance, currentLocation, drive.Root, context);
                            }
                            tracer.WriteLine("Parent path = {0}", new object[] { currentLocation });
                            path = path.Substring(2);
                            tracer.WriteLine("path = {0}", new object[] { path });
                            flag = true;
                            if (path.Length != 0)
                            {
								if (!flag7) {
	                                if ((path[0] == '\\') || (path[0] == '/'))
	                                {
	                                    path = path.Substring(1);
	                                }
								}
                                tracer.WriteLine("path = {0}", new object[] { path });
                                if (path.Length != 0)
                                {
                                    goto Label_024B;
                                }
                            }
                            goto Label_0260;
                        }
                        if (path.Equals(".", StringComparison.OrdinalIgnoreCase))
                        {
                            flag = true;
                            path = string.Empty;
                            goto Label_0260;
                        }
                        if (path.StartsWith(@".\", StringComparison.Ordinal) || path.StartsWith("./", StringComparison.Ordinal))
                        {
                            path = path.Substring(@".\".Length);
                            flag = true;
                            tracer.WriteLine("path = {0}", new object[] { path });
                            if (path.Length == 0)
                            {
                                goto Label_0260;
                            }
                        }
                        if ((path.Length == 0) || !flag)
                        {
                            goto Label_0260;
                        }
                        goto Label_024B;
                    }
                }
                else
                {
                    currentLocation = string.Empty;
                    path = path.Substring(1);
                    tracer.WriteLine("path = {0}", new object[] { path });
                }
            }
        Label_0260:
            if (!string.IsNullOrEmpty(path))
            {
                currentLocation = this.sessionState.Internal.MakePath(providerInstance, currentLocation, path, context);
            }
            NavigationCmdletProvider provider = providerInstance as NavigationCmdletProvider;
            if (provider != null)
            {
                string str2 = this.sessionState.Internal.MakePath(context.Drive.Root, currentLocation, context);
                string str3 = provider.ContractRelativePath(str2, context.Drive.Root, false, context);
                if (!string.IsNullOrEmpty(str3))
                {
					flag1 = OSHelper.IsUnix && context.Drive.Root.StartsWith ("/");
					if (!flag1 && str3.StartsWith(context.Drive.Root, StringComparison.Ordinal))
                    {
                        currentLocation = str3.Substring(context.Drive.Root.Length);
                    }
                    else
                    {
                        currentLocation = str3;
                    }
                }
                else
                {
                    currentLocation = "";
                }
            }
            tracer.WriteLine("result = {0}", new object[] { currentLocation });
            return currentLocation;
        }
Example #24
0
 internal Collection<string> GetGlobbedProviderPathsFromProviderPath(string path, bool allowNonexistingPaths, string providerId, CmdletProviderContext context, out CmdletProvider providerInstance)
 {
     providerInstance = null;
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     if (providerId == null)
     {
         throw PSTraceSource.NewArgumentNullException("providerId");
     }
     if (context == null)
     {
         throw PSTraceSource.NewArgumentNullException("context");
     }
     using (pathResolutionTracer.TraceScope("Resolving PROVIDER-INTERNAL path \"{0}\" to PROVIDER-INTERNAL path", new object[] { path }))
     {
         TraceFilters(context);
         return this.ResolveProviderPathFromProviderPath(path, providerId, allowNonexistingPaths, context, out providerInstance);
     }
 }
Example #25
0
        /// <summary>
        /// Constructor for the content stream
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the file to get the content from.
        /// </param>
        /// 
        /// <param name="streamName">
        /// The name of the Alternate Data Stream to get the content from. If null or empty, returns
        /// the file's primary content.
        /// </param>
        /// 
        /// <param name="mode">
        /// The file mode to open the file with.
        /// </param>
        /// 
        /// <param name="access">
        /// The file access requested in the file.
        /// </param>
        /// 
        /// <param name="share">
        /// The file share to open the file with
        /// </param>
        ///
        /// <param name="encoding">
        /// The encoding of the file to be read or written.
        /// </param>
        /// 
        /// <param name="usingByteEncoding">
        /// If true, bytes will be read from the file. If false, the specified encoding
        /// will be used to read the file.
        /// </param>
        /// 
        /// <param name="waitForChanges">
        /// If true, we will perform blocking reads on the file, waiting for new content to be appended
        /// </param>
        /// 
        /// <param name="provider">
        /// The CmdletProvider invoking this stream
        /// </param>
        /// 
        /// <param name="isRawStream">
        /// Indicates raw stream.
        /// </param>
        /// 
        public FileSystemContentReaderWriter(
            string path, string streamName, FileMode mode, FileAccess access, FileShare share,
            Encoding encoding, bool usingByteEncoding, bool waitForChanges, CmdletProvider provider,
            bool isRawStream)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            if (s_tracer.IsEnabled)
            {
                s_tracer.WriteLine("path = {0}", path);
                s_tracer.WriteLine("mode = {0}", mode);
                s_tracer.WriteLine("access = {0}", access);
            }

            _path = path;
            _streamName = streamName;
            _mode = mode;
            _access = access;
            _share = share;
            _encoding = encoding;
            _usingByteEncoding = usingByteEncoding;
            _waitForChanges = waitForChanges;
            _provider = provider;
            _isRawStream = isRawStream;

            CreateStreams(path, streamName, mode, access, share, encoding);
        }
Example #26
0
        private void InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider)
        {
            List<PSDriveInfo> drives = new List<PSDriveInfo>();
            DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider;

            if (driveProvider != null)
            {
                Collection<PSDriveInfo> collection = driveProvider.DoInitializeDefaultDrives();
                if ((collection != null) && (collection.Count > 0))
                {
                    drives.AddRange(collection);
                    _providersCurrentDrive[provider] = collection[0];
                }
            }

            if (drives.Count > 0)
            {
                foreach (PSDriveInfo driveInfo in drives)
                {
                    if (driveInfo != null)
                    {
                        // TODO: need to set driveInfo.Root
                        // TODO:this should be automatically called when using DriveIntrinsics.New! #providerSupport
                        driveProvider.DoNewDrive(driveInfo);

                        try
                        {
                            //always to global scope
                            _executionContext.SessionState.Drive.New(driveInfo,
                                SessionStateScope<PSDriveInfo>.ScopeSpecifiers.Global.ToString());
                        }
                        catch
                        {
                            // TODO: What should we do if the drive name is not unique?
                            // => I guess overwrite the old one and write a warning (however this works from here)
                        }
                    }
                }
            }
        }
Example #27
0
 private Collection<PathInfo> ResolveDriveQualifiedPath(string path, CmdletProviderContext context, bool allowNonexistingPaths, out CmdletProvider providerInstance)
 {
     providerInstance = null;
     PSDriveInfo workingDriveForPath = null;
     Collection<PathInfo> collection = new Collection<PathInfo>();
     pathResolutionTracer.WriteLine("Path is DRIVE-QUALIFIED", new object[0]);
     string str = this.GetDriveRootRelativePathFromPSPath(path, context, true, out workingDriveForPath, out providerInstance);
     pathResolutionTracer.WriteLine("DRIVE-RELATIVE path: {0}", new object[] { str });
     pathResolutionTracer.WriteLine("Drive: {0}", new object[] { workingDriveForPath.Name });
     pathResolutionTracer.WriteLine("Provider: {0}", new object[] { workingDriveForPath.Provider });
     context.Drive = workingDriveForPath;
     providerInstance = this.sessionState.Internal.GetContainerProviderInstance(workingDriveForPath.Provider);
     ContainerCmdletProvider provider = providerInstance as ContainerCmdletProvider;
     ItemCmdletProvider provider2 = providerInstance as ItemCmdletProvider;
     ProviderInfo providerInfo = providerInstance.ProviderInfo;
     string item = null;
     string providerPath = null;
     if (workingDriveForPath.Hidden)
     {
         item = GetProviderQualifiedPath(str, providerInfo);
         providerPath = str;
     }
     else
     {
         item = GetDriveQualifiedPath(str, workingDriveForPath);
         providerPath = this.GetProviderPath(path, context);
     }
     pathResolutionTracer.WriteLine("PROVIDER path: {0}", new object[] { providerPath });
     Collection<string> collection2 = new Collection<string>();
     if (!context.SuppressWildcardExpansion)
     {
         if (CmdletProviderManagementIntrinsics.CheckProviderCapabilities(ProviderCapabilities.ExpandWildcards, providerInfo))
         {
             pathResolutionTracer.WriteLine("Wildcard matching is being performed by the provider.", new object[0]);
             if ((provider2 != null) && WildcardPattern.ContainsWildcardCharacters(str))
             {
                 foreach (string str4 in provider2.ExpandPath(providerPath, context))
                 {
                     collection2.Add(this.GetDriveRootRelativePathFromProviderPath(str4, workingDriveForPath, context));
                 }
             }
             else
             {
                 collection2.Add(this.GetDriveRootRelativePathFromProviderPath(providerPath, workingDriveForPath, context));
             }
         }
         else
         {
             pathResolutionTracer.WriteLine("Wildcard matching is being performed by the engine.", new object[0]);
             collection2 = this.ExpandMshGlobPath(str, allowNonexistingPaths, workingDriveForPath, provider, context);
         }
     }
     else if (provider2 != null)
     {
         if (allowNonexistingPaths || provider2.ItemExists(providerPath, context))
         {
             collection2.Add(item);
         }
     }
     else
     {
         collection2.Add(item);
     }
     if ((((!allowNonexistingPaths && (collection2.Count < 1)) && !WildcardPattern.ContainsWildcardCharacters(path)) && ((context.Include == null) || (context.Include.Count == 0))) && ((context.Exclude == null) || (context.Exclude.Count == 0)))
     {
         ItemNotFoundException exception = new ItemNotFoundException(path, "PathNotFound", SessionStateStrings.PathNotFound);
         pathResolutionTracer.TraceError("Item does not exist: {0}", new object[] { path });
         throw exception;
     }
     foreach (string str5 in collection2)
     {
         if (context.Stopping)
         {
             throw new PipelineStoppedException();
         }
         item = null;
         if (workingDriveForPath.Hidden)
         {
             if (IsProviderDirectPath(str5))
             {
                 item = str5;
             }
             else
             {
                 item = GetProviderQualifiedPath(str5, providerInfo);
             }
         }
         else
         {
             item = GetDriveQualifiedPath(str5, workingDriveForPath);
         }
         collection.Add(new PathInfo(workingDriveForPath, providerInfo, item, this.sessionState));
         pathResolutionTracer.WriteLine("RESOLVED PATH: {0}", new object[] { item });
     }
     return collection;
 }
Example #28
0
        private void InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider)
        {
            List<PSDriveInfo> drives = new List<PSDriveInfo>();
            DriveCmdletProvider driveProvider = providerInstance as DriveCmdletProvider;

            if (driveProvider != null)
            {
                Collection<PSDriveInfo> collection = driveProvider.DoInitializeDefaultDrives();
                if ((collection != null) && (collection.Count > 0))
                {
                    drives.AddRange(collection);
                    _providersCurrentDrive[provider] = collection[0];
                }
            }

            if (drives.Count > 0)
            {
                foreach (PSDriveInfo driveInfo in drives)
                {
                    if (driveInfo != null)
                    {
                        // TODO: need to set driveInfo.Root

                        driveProvider.DoNewDrive(driveInfo);

                        try
                        {
                            _drives.Add(driveInfo.Name, driveInfo);
                        }
                        catch
                        {
                            // TODO: What should we do if the drive name is not unique?
                        }
                    }
                }
            }
        }
Example #29
0
 private Collection<string> ResolveProviderPathFromProviderPath(string providerPath, string providerId, bool allowNonexistingPaths, CmdletProviderContext context, out CmdletProvider providerInstance)
 {
     providerInstance = this.sessionState.Internal.GetProviderInstance(providerId);
     ContainerCmdletProvider containerProvider = providerInstance as ContainerCmdletProvider;
     ItemCmdletProvider provider2 = providerInstance as ItemCmdletProvider;
     Collection<string> collection = new Collection<string>();
     if (!context.SuppressWildcardExpansion)
     {
         if (CmdletProviderManagementIntrinsics.CheckProviderCapabilities(ProviderCapabilities.ExpandWildcards, providerInstance.ProviderInfo))
         {
             pathResolutionTracer.WriteLine("Wildcard matching is being performed by the provider.", new object[0]);
             if ((provider2 != null) && WildcardPattern.ContainsWildcardCharacters(providerPath))
             {
                 collection = new Collection<string>(provider2.ExpandPath(providerPath, context));
             }
             else
             {
                 collection.Add(providerPath);
             }
         }
         else
         {
             pathResolutionTracer.WriteLine("Wildcard matching is being performed by the engine.", new object[0]);
             if (containerProvider != null)
             {
                 collection = this.GetGlobbedProviderPathsFromProviderPath(providerPath, allowNonexistingPaths, containerProvider, context);
             }
             else
             {
                 collection.Add(providerPath);
             }
         }
     }
     else if (provider2 != null)
     {
         if (allowNonexistingPaths || provider2.ItemExists(providerPath, context))
         {
             collection.Add(providerPath);
         }
     }
     else
     {
         collection.Add(providerPath);
     }
     if (((allowNonexistingPaths || (collection.Count >= 1)) || WildcardPattern.ContainsWildcardCharacters(providerPath)) || ((context.Include != null) && (context.Include.Count != 0)))
     {
         return collection;
     }
     if ((context.Exclude != null) && (context.Exclude.Count != 0))
     {
         return collection;
     }
     ItemNotFoundException exception = new ItemNotFoundException(providerPath, "PathNotFound", SessionStateStrings.PathNotFound);
     pathResolutionTracer.TraceError("Item does not exist: {0}", new object[] { providerPath });
     throw exception;
 }
Example #30
0
        private bool ItemExists(CmdletProvider provider, string path, ProviderRuntime providerRuntime)
        {
            ItemCmdletProvider itemProvider = provider as ItemCmdletProvider;

            if (itemProvider == null)
                return false;

            return itemProvider.ItemExists(path, providerRuntime);
        }
Example #31
0
 private Collection<PathInfo> ResolvePSPathFromProviderPath(string path, CmdletProviderContext context, bool allowNonexistingPaths, bool isProviderDirectPath, bool isProviderQualifiedPath, out CmdletProvider providerInstance)
 {
     Collection<PathInfo> collection = new Collection<PathInfo>();
     providerInstance = null;
     string providerId = null;
     PSDriveInfo drive = null;
     string providerPath = null;
     if (isProviderDirectPath)
     {
         pathResolutionTracer.WriteLine("Path is PROVIDER-DIRECT", new object[0]);
         providerPath = path;
         providerId = this.sessionState.Path.CurrentLocation.Provider.Name;
     }
     else if (isProviderQualifiedPath)
     {
         pathResolutionTracer.WriteLine("Path is PROVIDER-QUALIFIED", new object[0]);
         providerPath = ParseProviderPath(path, out providerId);
     }
     pathResolutionTracer.WriteLine("PROVIDER-INTERNAL path: {0}", new object[] { providerPath });
     pathResolutionTracer.WriteLine("Provider: {0}", new object[] { providerId });
     Collection<string> collection2 = this.ResolveProviderPathFromProviderPath(providerPath, providerId, allowNonexistingPaths, context, out providerInstance);
     drive = providerInstance.ProviderInfo.HiddenDrive;
     foreach (string str3 in collection2)
     {
         string str4 = str3;
         if (context.Stopping)
         {
             throw new PipelineStoppedException();
         }
         string str5 = null;
         if (IsProviderDirectPath(str4))
         {
             str5 = str4;
         }
         else
         {
             str5 = string.Format(CultureInfo.InvariantCulture, "{0}::{1}", new object[] { providerId, str4 });
         }
         collection.Add(new PathInfo(drive, providerInstance.ProviderInfo, str5, this.sessionState));
         pathResolutionTracer.WriteLine("RESOLVED PATH: {0}", new object[] { str5 });
     }
     return collection;
 }