Exemple #1
0
        private void doCopyTo(File to, object exclude, object overwrite)
        {
            // check exclude
            if (exclude is Regex)
            {
                if (((Regex)exclude).matches(m_uri.toStr()))
                {
                    return;
                }
            }
            else if (exclude is Func)
            {
                if (((Func)exclude).call(this) == Boolean.True)
                {
                    return;
                }
            }

            // check for overwrite
            if (to.exists())
            {
                if (overwrite is Boolean)
                {
                    if (overwrite == Boolean.False)
                    {
                        return;
                    }
                }
                else if (overwrite is Func)
                {
                    if (((Func)overwrite).call(this) == Boolean.False)
                    {
                        return;
                    }
                }
                else
                {
                    throw IOErr.make("No overwrite policy for `" + to + "`").val;
                }
            }

            // copy directory
            if (isDir())
            {
                to.create();
                List kids = list();
                for (int i = 0; i < kids.sz(); ++i)
                {
                    File kid = (File)kids.get(i);
                    kid.doCopyTo(to.plusNameOf(kid), exclude, overwrite);
                }
            }

            // copy file contents
            else
            {
                OutStream @out = to.@out();
                try
                {
                    @in().pipe(@out);
                }
                finally
                {
                    @out.close();
                }
            }
        }
Exemple #2
0
        private void doCopyTo(File to, object exclude, object overwrite)
        {
            // check exclude
              if (exclude is Regex)
              {
            if (((Regex)exclude).matches(m_uri.toStr())) return;
              }
              else if (exclude is Func)
              {
            if (((Func)exclude).call(this) == Boolean.True) return;
              }

              // check for overwrite
              if (to.exists())
              {
            if (overwrite is Boolean)
            {
              if (overwrite == Boolean.False) return;
            }
            else if (overwrite is Func)
            {
              if (((Func)overwrite).call(this) == Boolean.False) return;
            }
            else
            {
              throw IOErr.make("No overwrite policy for `" + to + "`").val;
            }
              }

              // copy directory
              if (isDir())
              {
            to.create();
            List kids = list();
            for (int i=0; i<kids.sz(); ++i)
            {
              File kid = (File)kids.get(i);
              kid.doCopyTo(to.plusNameOf(kid), exclude, overwrite);
            }
              }

              // copy file contents
              else
              {
            OutStream @out = to.@out();
            try
            {
              @in().pipe(@out);
            }
            finally
            {
              @out.close();
            }
              }
        }