protected override void GetItem(string path) { bool isContainer = false; if (string.IsNullOrEmpty(path)) { throw PSTraceSource.NewArgumentException("path"); } try { bool flag2 = false; FileSystemProviderGetItemDynamicParameters dynamicParameters = null; if (base.DynamicParameters != null) { dynamicParameters = base.DynamicParameters as FileSystemProviderGetItemDynamicParameters; if (dynamicParameters != null) { if ((dynamicParameters.Stream != null) && (dynamicParameters.Stream.Length > 0)) { flag2 = true; } else { int index = path.IndexOf(':'); int startIndex = path.IndexOf(':', index + 1); if (startIndex > 0) { string str = path.Substring(startIndex + 1); path = path.Remove(startIndex); flag2 = true; dynamicParameters = new FileSystemProviderGetItemDynamicParameters { Stream = new string[] { str } }; } } } } FileSystemInfo item = this.GetFileSystemItem(path, ref isContainer, false); if (item != null) { if (flag2) { if (!isContainer) { foreach (string str2 in dynamicParameters.Stream) { WildcardPattern pattern = new WildcardPattern(str2, WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase); bool flag3 = false; foreach (AlternateStreamData data in AlternateDataStreamUtilities.GetStreams(item.FullName)) { if (pattern.IsMatch(data.Stream)) { string str3 = item.FullName + ":" + data.Stream; base.WriteItemObject(data, str3, isContainer); flag3 = true; } } if (!WildcardPattern.ContainsWildcardCharacters(str2) && !flag3) { Exception exception = new FileNotFoundException(StringUtil.Format(FileSystemProviderStrings.AlternateDataStreamNotFound, str2, item.FullName), item.FullName); base.WriteError(new ErrorRecord(exception, "AlternateDataStreamNotFound", ErrorCategory.ObjectNotFound, path)); } } } } else { base.WriteItemObject(item, item.FullName, isContainer); } } else { Exception exception2 = new IOException(StringUtil.Format(FileSystemProviderStrings.ItemNotFound, path)); base.WriteError(new ErrorRecord(exception2, "ItemNotFound", ErrorCategory.ObjectNotFound, path)); } } catch (IOException exception3) { ErrorRecord errorRecord = new ErrorRecord(exception3, "GetItemIOError", ErrorCategory.ReadError, path); base.WriteError(errorRecord); } catch (UnauthorizedAccessException exception4) { base.WriteError(new ErrorRecord(exception4, "GetItemUnauthorizedAccessError", ErrorCategory.PermissionDenied, path)); } }
/// <summary> /// Gets the item at the specified path. /// </summary> /// /// <param name="path"> /// A fully qualified path representing a file or directory in the /// file system. /// </param> /// /// <returns> /// Nothing. FileInfo and DirectoryInfo objects are written to the /// context's pipeline. /// </returns> /// /// <exception cref="System.ArgumentException"> /// path is null or empty. /// </exception> protected override void GetItem(string path) { // Validate the argument bool isContainer = false; if (String.IsNullOrEmpty(path)) { // The parameter was null, throw an exception throw PSTraceSource.NewArgumentException("path"); } try { bool retrieveStreams = false; FileSystemProviderGetItemDynamicParameters dynamicParameters = null; if (DynamicParameters != null) { dynamicParameters = DynamicParameters as FileSystemProviderGetItemDynamicParameters; if (dynamicParameters != null) { if ((dynamicParameters.Stream != null) && (dynamicParameters.Stream.Length > 0)) { retrieveStreams = true; } else { // See if they've used the inline stream syntax. They have more than one colon. int firstColon = path.IndexOf(':'); int secondColon = path.IndexOf(':', firstColon + 1); if (secondColon > 0) { string streamName = path.Substring(secondColon + 1); path = path.Remove(secondColon); retrieveStreams = true; dynamicParameters = new FileSystemProviderGetItemDynamicParameters(); dynamicParameters.Stream = new string[] { streamName }; } } } } FileSystemInfo result = GetFileSystemItem(path, ref isContainer, false); if (result != null) { // If we want to retrieve the file streams, retrieve them. if (retrieveStreams) { if (!isContainer) { foreach (string desiredStream in dynamicParameters.Stream) { // See that it matches the name specified WildcardPattern p = WildcardPattern.Get(desiredStream, WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant); bool foundStream = false; foreach (AlternateStreamData stream in AlternateDataStreamUtilities.GetStreams(result.FullName)) { if (!p.IsMatch(stream.Stream)) { continue; } string outputPath = result.FullName + ":" + stream.Stream; WriteItemObject(stream, outputPath, isContainer); foundStream = true; } if ((!WildcardPattern.ContainsWildcardCharacters(desiredStream)) && (!foundStream)) { string errorMessage = StringUtil.Format( FileSystemProviderStrings.AlternateDataStreamNotFound, desiredStream, result.FullName); Exception e = new FileNotFoundException(errorMessage, result.FullName); WriteError(new ErrorRecord( e, "AlternateDataStreamNotFound", ErrorCategory.ObjectNotFound, path)); } } } } else { // Otherwise, return the item itself. WriteItemObject(result, result.FullName, isContainer); } } else { String error = StringUtil.Format(FileSystemProviderStrings.ItemNotFound, path); Exception e = new IOException(error); WriteError(new ErrorRecord( e, "ItemNotFound", ErrorCategory.ObjectNotFound, path)); } } catch (IOException ioError) { //IOException contains specific message about the error occured and so no need for errordetails. ErrorRecord er = new ErrorRecord(ioError, "GetItemIOError", ErrorCategory.ReadError, path); WriteError(er); } catch (UnauthorizedAccessException accessException) { WriteError(new ErrorRecord(accessException, "GetItemUnauthorizedAccessError", ErrorCategory.PermissionDenied, path)); } } // GetItem