protected override void ProcessPath(PscxPathInfo pscxPath) { try { foreach (string aName in Name) { if (!FileSystem.AlternateDataStreamExists(pscxPath.ProviderPath, aName)) { this.ErrorHandler.WriteAlternateDataStreamDoentExist(aName, pscxPath.ProviderPath); continue; } string filename = System.IO.Path.GetFileName(pscxPath.ProviderPath); if (this.ShouldProcess(filename, "removing alternate data stream " + aName)) { FileSystem.DeleteAlternateDataStream(pscxPath.ProviderPath, aName); } } } catch (SecurityException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (UnauthorizedAccessException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.NotSpecified, pscxPath.ProviderPath)); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { if (ShouldProcess(pscxPath.ProviderPath)) { _writer.ProcessPath(pscxPath); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { FileHandler.ProcessRead(pscxPath.ProviderPath, delegate(Stream stream) { WriteHash(_hashAlgorithm.ComputeHash(stream), pscxPath.ProviderPath); }); }
protected override void ProcessPath(PscxPathInfo pscxPath) { try { WriteVerbose("Processing " + pscxPath.ProviderPath); bool exists = FileSystem.AlternateDataStreamExists(pscxPath.ProviderPath, Name); WriteObject(exists); } catch (SecurityException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (UnauthorizedAccessException ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.SecurityError, pscxPath.ProviderPath)); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FileError", ErrorCategory.NotSpecified, pscxPath.ProviderPath)); } }
protected override void BeginProcessing() { base.BeginProcessing(); RegisterInputType <ArchiveEntry>(ProcessArchive); RegisterInputType <FileInfo>(ProcessArchive); // if OutputPath is not provided, use current filesystem path. if (OutputPath == null) { OutputPath = PscxPathInfo.FromPathInfo(this.CurrentProviderLocation(FileSystemProvider.ProviderName)); // todo: localize WriteVerbose("Using FileSystemProvider current location for OutputPath: " + OutputPath); } string sevenZDll = PscxContext.Instance.Is64BitProcess ? "7z64.dll" : "7z.dll"; string sevenZPath = System.IO.Path.Combine(PscxContext.Instance.Home, sevenZDll); if (SevenZipBase.CurrentLibraryFeatures == LibraryFeature.None) { Trace.Assert(File.Exists(sevenZPath), sevenZPath + " not found or inaccessible."); SevenZipBase.SetLibraryPath(sevenZPath); // can only call this once per appdomain } WriteDebug("7zip path: " + sevenZPath); WriteDebug("7zip features: " + SevenZipBase.CurrentLibraryFeatures); }
/// <summary> /// /// </summary> /// <param name="literalPath">A PSPath; A PSPath is always literal/resolved.</param> /// <returns></returns> /// <remarks>Path argument must be a resolved path (e.g. from PSPath property on input object).</remarks> protected PscxPathInfo GetPscxPathInfoFromPSPath(string literalPath) { //new PscxPathInfo(path, this.SessionState); PscxPathInfo pscxPath = PscxPathInfo.GetPscxPathInfo(this.SessionState, literalPath); return(pscxPath); }
protected override void ProcessPath(PscxPathInfo pscxPath) { FileHandler.ProcessRead(pscxPath.ProviderPath, delegate(Stream stream) { Bitmap bmp = new Bitmap(stream); WriteObject(bmp); }); }
public override void ProcessFile(FileInfo file) { if (file.FullName == _archivePath) { return; } _currentInputFile = file.Name; string fullPath; if (Command.ParameterSetName == "Object") { // get specified entry path root, default to CWD if null. string root = (Command.EntryPathRoot ?? PscxPathInfo.GetPscxPathInfo(Command.SessionState, ".")).ProviderPath; if (file.FullName.StartsWith(root)) { // trim off the start root fullPath = file.FullName.Remove(0, root.Length) .Replace('\\', Path.AltDirectorySeparatorChar) // flip slashes .TrimStart(Path.AltDirectorySeparatorChar); // remove leading slash Command.WriteVerbose("ProcessFile: " + fullPath); } else { // file falls outside of root, so error out Command.ErrorHandler.WriteFileError( file.FullName, new ArgumentException( String.Format( Properties.Resources.InputFileOutsideOfRoot, file.Name, root))); return; } } else { // literalpath / path parameterset fullPath = Path.Combine(CurrentPath, _currentInputFile); } if (!IsExcludedPath(file.FullName)) { OpenEntry(_compressedOutputStream, fullPath); Command.FileHandler.ProcessRead(file, delegate(Stream inputStream) { WriteStream(inputStream, _compressedOutputStream); ExcludePath(file.FullName); }); CloseEntry(_compressedOutputStream); } }
private static bool DeleteFileOrDirectory(PscxPathInfo pscxPath, FileSystemInfo fi) { if (fi is DirectoryInfo) { return(NativeMethods.RemoveDirectory(pscxPath.ProviderPath)); } return(NativeMethods.DeleteFile(pscxPath.ProviderPath)); }
protected override void ProcessPath(PscxPathInfo pscxPath) { string filePath = pscxPath.ProviderPath; if (ShouldProcess(filePath)) { ConvertLineEndingFromFile(filePath); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { string filePath = pscxPath.ProviderPath; FileHandler.ProcessRead(filePath, delegate(Stream stream) { ProcessPathImpl(filePath, stream); }); }
protected SevenZipBaseEx(PscxCmdlet command, FileInfo file, ArchiveFormat format) { //Debug.Assert(format != ArchiveFormat.Unknown, "format != ArchiveFormat.Unknown"); _command = command; _file = file; _format = format; _archivePscxPath = PscxPathInfo.GetPscxPathInfo(_command.SessionState, file.FullName); }
/// <summary> /// /// </summary> /// <param name="directory"></param> public virtual void ProcessDirectory(DirectoryInfo directory) { if (Command.ParameterSetName != PscxInputObjectPathCommandBase.ParameterSetObject) { foreach (string path in Directory.GetFileSystemEntries(directory.FullName)) { ProcessPath(PscxPathInfo.GetPscxPathInfo(Command.SessionState, path)); } } }
private void ValidatePscxPaths() { _boundPaths = new List <Pair <PropertyInfo, PscxPathAttribute> >(); var visitor = new Visitor(this); visitor.VisitType(GetType()); foreach (var boundPath in _boundPaths) { PropertyInfo parameter = boundPath.First; string parameterName = parameter.Name; // retrieve [PscxPath] attribute PscxPathAttribute pathAttrib = boundPath.Second; // get property value object value = parameter.GetValue(this, null); if ((value != null) && // allow runtime modification from derived classes OnValidatePscxPath(parameterName, pathAttrib)) { WriteDebug("Validating " + parameterName); PscxPathInfo[] pscxPaths = null; // may be array if (value is Array) { pscxPaths = value as PscxPathInfo[]; } else { var pscxPath = value as PscxPathInfo; if (pscxPath != null) { pscxPaths = new PscxPathInfo[] { pscxPath }; } } if (pscxPaths != null) { foreach (PscxPathInfo pscxPath in pscxPaths) { ValidatePscxPath(parameterName, pathAttrib, pscxPath); } } } else { WriteDebug("Skipping " + parameterName); } } }
protected override void ProcessPath(PscxPathInfo pscxPath) { var name = ReparsePointHelper.EnsurePathSlash(pscxPath.ProviderPath); if (!NativeMethods.DeleteVolumeMountPoint(name)) { ErrorHandler.WriteLastWin32Error("DeleteVolumeMountPointFailed", name); } base.ProcessPath(pscxPath); }
protected override void ProcessPath(PscxPathInfo pscxPath) { FileHandler.ProcessRead(pscxPath.ProviderPath, delegate(Stream stream) { using (var streamReader = new StreamReader(stream)) { string script = streamReader.ReadToEnd(); TestScript(script, pscxPath.ToPathInfo().Path); } }); }
protected override void ProcessPath(PscxPathInfo pscxPath) { string filePath = pscxPath.ProviderPath; if (ShouldProcess(filePath + ". Update " + _updateType + " time.")) { ChangeFileTimes(filePath); if (_passThru) { WriteObject(new FileInfo(filePath)); } } }
protected override void ProcessPath(PscxPathInfo pscxPath) { string filePath = pscxPath.ProviderPath; if (File.Exists(filePath)) { WriteObject(FileVersionInfo.GetVersionInfo(filePath)); } else if (!Directory.Exists(filePath)) { ErrorHandler.WriteFileNotFoundError(filePath); } }
private void ValidatePathType(string parameterName, PscxPathInfo pscxPath, PscxPathType pathType, PscxPathType expectedPathType) { WriteDebug("ValidatePathType: expecting " + pathType); if ((pathType & expectedPathType) != pathType) { // TODO: localize string description = String.Format("Path type is {0}; expecting {1}", pathType, expectedPathType); // path type violation (terminating) OnPscxPathError(parameterName, description, PscxPathState.InvalidPathType, pscxPath); } }
public override void ProcessDirectory(DirectoryInfo directory) { string fullPath; if (Command.ParameterSetName == "Object") { // get specified entry path root, default to CWD if null. string root = (Command.EntryPathRoot ?? PscxPathInfo.GetPscxPathInfo(Command.SessionState, ".")).ProviderPath; if (directory.FullName.StartsWith(root)) { // trim off the start root fullPath = directory.FullName.Remove(0, root.Length) .Replace('\\', Path.AltDirectorySeparatorChar) // flip slashes .TrimStart(Path.AltDirectorySeparatorChar); // remove leading slash } else { // file falls outside of root, so error out Command.ErrorHandler.WriteFileError( directory.FullName, new ArgumentException( String.Format( Properties.Resources.InputFileOutsideOfRoot, directory.Name, root))); return; } Command.WriteVerbose("ProcessFile: " + fullPath); } else { // note: unix style separator used for ziplib (tar, zip directories etc) string name = directory.Name + Path.AltDirectorySeparatorChar; string fullName = CurrentPath + name; OpenEntry(_compressedOutputStream, fullName); _currentPath.Add(name); base.ProcessDirectory(directory); CloseEntry(_compressedOutputStream); _currentPath.RemoveAt(_currentPath.Count - 1); } }
protected override void ProcessRecord() { CurrentPscxPathInfo = null; // changed to use separate backing variables for Path and LiteralPath // so PscxCmdlet's ValidatePscxPath routines can detect the parameterset // in use without knowledge of this derived class. (oisin) PscxPathInfo[] paths = GetSelectedPathParameter(this.ParameterSetName); foreach (PscxPathInfo pscxPath in paths) { WriteDebug(String.Format("{0} processing pscxPath '{1}'", this.CmdletName, pscxPath)); CurrentPscxPathInfo = pscxPath; ProcessPath(pscxPath); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { string filePath = pscxPath.ProviderPath; try { string shortPath = Utils.GetShortPathName(filePath); var shortPathInfo = new ShortPathInfo(filePath, shortPath); WriteObject(shortPathInfo); } catch (IOException exc) { ErrorHandler.HandleFileError(false, filePath, exc); } }
/// <summary> /// /// </summary> /// <param name="pscxPath"></param> public virtual void ProcessPath(PscxPathInfo pscxPath) { DirectoryInfo dir = new DirectoryInfo(pscxPath.ProviderPath); FileInfo file = new FileInfo(pscxPath.ProviderPath); if (dir.Exists) { ProcessDirectory(dir); } if (file.Exists) { ProcessFile(file); } }
private object TransformInternal(EngineIntrinsics engineIntrinsics, string[] boundPaths, bool inputIsPathArray) { object outputData; SessionState session = engineIntrinsics.SessionState; PscxPathInfo[] pscxPaths = PscxPathInfo.GetPscxPathInfos(session, boundPaths, _noGlobbing); // NOTE: this should never happen - verify if (pscxPaths.Length == 0) { Trace.WriteLine("TransformInternal: path count is zero."); return(pscxPaths); } if (_asString) { // String var paths = new List <string>(pscxPaths.Length); Array.ForEach(pscxPaths, pscxPath => paths.Add(pscxPath.ToString())); if (inputIsPathArray || (!_noGlobbing)) { outputData = paths; } else { // only literal can return a scalar outputData = paths[0]; } } else { // PscxPathInfo if (inputIsPathArray || (!_noGlobbing)) { outputData = pscxPaths; } else { // only literal can return a scalar outputData = pscxPaths[0]; } } return(outputData); }
protected override void ProcessPath(PscxPathInfo pscxPath) { var filePath = pscxPath.ProviderPath; if (ReparsePointHelper.IsReparsePoint(filePath)) { if (Raw) { WriteObject(ReparsePointHelper.GetReparsePointData(filePath)); } else { WriteObject(ReparsePointHelper.GetReparsePoint(filePath)); } } }
protected override void BeginProcessing() { base.BeginProcessing(); RegisterInputType <ArchiveEntry>(ProcessArchive); RegisterInputType <FileInfo>(ProcessArchive); // if OutputPath is not provided, use current filesystem path. if (OutputPath == null) { OutputPath = PscxPathInfo.FromPathInfo( this.CurrentProviderLocation(FileSystemProvider.ProviderName)); // todo: localize WriteVerbose("Using FileSystemProvider current location for OutputPath: " + OutputPath); } }
protected void RegisterPathInputType <T>() { RegisterInputType <T>(delegate { if (CurrentInputObjectPath == null) { return; } PscxPathInfo pscxPath = GetPscxPathInfoFromPSPath(CurrentInputObjectPath); if (InputSettings.ConstrainInputObjectByPSPath) { CheckProviderConstraints(pscxPath, null, "InputObject"); } ProcessPath(pscxPath); }); }
protected SevenZipBaseEx(PscxCmdlet command, FileInfo file, InArchiveFormat format) { //Debug.Assert(format != ArchiveFormat.Unknown, "format != ArchiveFormat.Unknown"); _command = command; _file = file; _format = format; _archivePscxPath = PscxPathInfo.GetPscxPathInfo(_command.SessionState, file.FullName); string sevenZDll = PscxContext.Instance.Is64BitProcess ? "7z64.dll" : "7z.dll"; string sevenZPath = Path.Combine(PscxContext.Instance.Home, sevenZDll); Trace.Assert(File.Exists(sevenZPath), sevenZPath + " not found or inaccessible."); SevenZipBase.SetLibraryPath(sevenZPath); _extractor = new SevenZipExtractor(file.FullName); }
private void ValidateExists(string parameterName, PscxPathInfo pscxPath, ref PscxPathType pathType) { WriteDebug("ValidateExists"); bool exists = PscxPathInfo.Exists(pscxPath, ref pathType); if (!exists) { // TODO: localize string description = String.Format( "The path '{0}' supplied for {1} must exist.", pscxPath, parameterName); // terminates by default (unless overridden) OnPscxPathError(parameterName, description, PscxPathState.NotExist, pscxPath); } }
protected override void ProcessPath(PscxPathInfo pscxPath) { Assembly assembly = null; string filePath = pscxPath.ProviderPath; try { assembly = Assembly.LoadFrom(filePath); } catch (PipelineStoppedException) { throw; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "FailedAssemblyLoadFrom", ErrorCategory.InvalidArgument, filePath)); return; } ProcessAssembly(assembly); }