Beispiel #1
0
        public void DeleteDirectory(string path, bool recursive)
        {
            if (DirectoryExists(path) == false)
            {
                return;
            }
            var normPath = NormPath(path);

            if (recursive)
            {
                Nodes[normPath] = new ShadowNode(true, true);
                var remove = Nodes.Where(x => IsDescendant(normPath, x.Key)).ToList();
                foreach (var kvp in remove)
                {
                    Nodes.Remove(kvp.Key);
                }
                Delete(path, true);
            }
            else
            {
                if (Nodes.Any(x => IsChild(normPath, x.Key) && x.Value.IsExist) || // shadow content
                    _fs.GetDirectories(path).Any() || _fs.GetFiles(path).Any())    // actual content
                {
                    throw new InvalidOperationException("Directory is not empty.");
                }
                Nodes[path] = new ShadowNode(true, true);
                var remove = Nodes.Where(x => IsChild(normPath, x.Key)).ToList();
                foreach (var kvp in remove)
                {
                    Nodes.Remove(kvp.Key);
                }
                Delete(path, false);
            }
        }
Beispiel #2
0
 public void DeleteFile(string path)
 {
     if (FileExists(path) == false)
     {
         return;
     }
     Nodes[NormPath(path)] = new ShadowNode(true, false);
 }
Beispiel #3
0
        public ICallGraphNode CreateShadowCopy()
        {
            if (shadowNode == null)
            {
                shadowNode = new ShadowNode(this);
            }

            return(shadowNode);
        }
Beispiel #4
0
    static ShadowNode theShadowKnows(dynamic realnode, ShadowNode parent)
    {
        ShadowNode shadow = new ShadowNode(realnode, parent);

        foreach (var c in realnode.Children)
        {
            shadow.Children.Add(theShadowKnows(c, shadow));
        }
        return(shadow);
    }
Beispiel #5
0
 private void Delete(string path, bool recurse)
 {
     foreach (var file in _fs.GetFiles(path))
     {
         Nodes[NormPath(file)] = new ShadowNode(true, false);
     }
     foreach (var dir in _fs.GetDirectories(path))
     {
         Nodes[NormPath(dir)] = new ShadowNode(true, true);
         if (recurse)
         {
             Delete(dir, true);
         }
     }
 }
    public void AddFile(string path, Stream stream, bool overrideIfExists)
    {
        var normPath = NormPath(path);

        if (Nodes.TryGetValue(normPath, out ShadowNode? sf) && sf.IsExist && (sf.IsDir || overrideIfExists == false))
        {
            throw new InvalidOperationException(string.Format("A file at path '{0}' already exists", path));
        }

        var parts = normPath.Split(Constants.CharArrays.ForwardSlash);

        for (var i = 0; i < parts.Length - 1; i++)
        {
            var dirPath = string.Join("/", parts.Take(i + 1));
            if (Nodes.TryGetValue(dirPath, out ShadowNode? sd))
            {
                if (sd.IsFile)
                {
                    throw new InvalidOperationException("Invalid path.");
                }

                if (sd.IsDelete)
                {
                    Nodes[dirPath] = new ShadowNode(false, true);
                }
            }
            else
            {
                if (Inner.DirectoryExists(dirPath))
                {
                    continue;
                }

                if (Inner.FileExists(dirPath))
                {
                    throw new InvalidOperationException("Invalid path.");
                }

                Nodes[dirPath] = new ShadowNode(false, true);
            }
        }

        _sfs.AddFile(path, stream, overrideIfExists);
        Nodes[normPath] = new ShadowNode(false, false);
    }
Beispiel #7
0
        public void AddFile(string path, string physicalPath, bool overrideIfExists = true, bool copy = false)
        {
            ShadowNode sf;
            var        normPath = NormPath(path);

            if (Nodes.TryGetValue(normPath, out sf) && sf.IsExist && (sf.IsDir || overrideIfExists == false))
            {
                throw new InvalidOperationException(string.Format("A file at path '{0}' already exists", path));
            }

            var parts = normPath.Split('/');

            for (var i = 0; i < parts.Length - 1; i++)
            {
                var        dirPath = string.Join("/", parts.Take(i + 1));
                ShadowNode sd;
                if (Nodes.TryGetValue(dirPath, out sd))
                {
                    if (sd.IsFile)
                    {
                        throw new InvalidOperationException("Invalid path.");
                    }
                    if (sd.IsDelete)
                    {
                        Nodes[dirPath] = new ShadowNode(false, true);
                    }
                }
                else
                {
                    if (_fs.DirectoryExists(dirPath))
                    {
                        continue;
                    }
                    if (_fs.FileExists(dirPath))
                    {
                        throw new InvalidOperationException("Invalid path.");
                    }
                    Nodes[dirPath] = new ShadowNode(false, true);
                }
            }

            _sfs.AddFile(path, physicalPath, overrideIfExists, copy);
            Nodes[normPath] = new ShadowNode(false, false);
        }
Beispiel #8
0
    public static void dumpIt(dynamic root)
    {
        ShadowNode sroot = theShadowKnows(root, null);

        using (StreamWriter wr = new StreamWriter("tree.dot"))
        {
            wr.Write("digraph d{\n");
            wr.Write("node [shape=box];\n");
            sroot.walk((n) =>
            {
                wr.Write("n" + n.unique + " [label=\"");
                string sym = n.realNode.Symbol;
                sym        = sym.Replace("\"", "\\\"");
                wr.Write(sym);
                if (n.realNode.Token != null)
                {
                    var tok = n.realNode.Token;
                    var lex = tok.Lexeme;
                    lex     = lex.Replace("\\", "\\\\");
                    lex     = lex.Replace("\n", "\\n");
                    lex     = lex.Replace("\"", "\\\"");
                    wr.Write("\\n");
                    wr.Write(lex);
                }
                wr.Write("\"");
                if (n.realNode.Token != null)
                {
                    wr.Write(",style=filled,fillcolor=\"#c0c0c0\"");
                }
                wr.Write("];\n");
            });

            sroot.walk((n) =>
            {
                if (n.parent != null)
                {
                    wr.Write("n" + n.parent.unique + "->n" + n.unique + ";\n");
                }
            });

            wr.Write("}\n");
        }
    }
Beispiel #9
0
 public ShadowNode(dynamic r, ShadowNode parent)
 {
     this.realNode = r;
     this.unique   = ctr++;
     this.parent   = parent;
 }
Beispiel #10
0
 public void ResetShadowCopy()
 {
     shadowNode = null;
 }