From f8eb4fa44cb42b73972716ce4bb0c3b27cfa4f22 Mon Sep 17 00:00:00 2001 From: "racham%netscape.com" Date: Mon, 5 Jul 1999 01:39:42 +0000 Subject: [PATCH] Adding RecursiveCopy interface git-svn-id: svn://10.0.0.236/trunk@38347 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsFileSpec.h | 1 + mozilla/xpcom/io/nsFileSpecMac.cpp | 45 +++++++++++++++++++++++++++++ mozilla/xpcom/io/nsFileSpecUnix.cpp | 45 +++++++++++++++++++++++++++++ mozilla/xpcom/io/nsFileSpecWin.cpp | 44 ++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) diff --git a/mozilla/xpcom/io/nsFileSpec.h b/mozilla/xpcom/io/nsFileSpec.h index d231648877e..4fb4508aca8 100644 --- a/mozilla/xpcom/io/nsFileSpec.h +++ b/mozilla/xpcom/io/nsFileSpec.h @@ -464,6 +464,7 @@ class NS_COM nsFileSpec void CreateDir(int mode = 0700) { CreateDirectory(mode); } // workaround for yet another VC++ bug with long identifiers. void Delete(PRBool inRecursive) const; + void RecursiveCopy(nsFileSpec newDir) const; nsresult Rename(const char* inNewName); // not const: gets updated nsresult Rename(const nsString& inNewName) diff --git a/mozilla/xpcom/io/nsFileSpecMac.cpp b/mozilla/xpcom/io/nsFileSpecMac.cpp index 461c1d50a86..e0bba25ca08 100644 --- a/mozilla/xpcom/io/nsFileSpecMac.cpp +++ b/mozilla/xpcom/io/nsFileSpecMac.cpp @@ -905,6 +905,51 @@ void nsFileSpec::Delete(PRBool inRecursive) const } // nsFileSpec::Delete +//---------------------------------------------------------------------------------------- +void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const +//---------------------------------------------------------------------------------------- +{ + if (IsDirectory()) + { + if (!(newDir.Exists())) + { + newDir.CreateDirectory(); + } + + for (nsDirectoryIterator i(*this); i.Exists(); i++) + { + nsFileSpec& child = (nsFileSpec&)i; + + if (child.IsDirectory()) + { + nsFileSpec tmpDirSpec(newDir); + + char *leafname = child.GetLeafName(); + tmpDirSpec += leafname; + nsCRT::free(leafname); + + child.RecursiveCopy(tmpDirSpec); + } + else + { + child.RecursiveCopy(newDir); + } + } + } + else if (!mPath.IsEmpty()) + { + nsFileSpec& filePath = (nsFileSpec&) *this; + + if (!(newDir.Exists())) + { + newDir.CreateDirectory(); + } + + filePath.Copy(newDir); + } +} // nsFileSpec::RecursiveCopy + + //---------------------------------------------------------------------------------------- nsresult nsFileSpec::Rename(const char* inNewName) //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsFileSpecUnix.cpp b/mozilla/xpcom/io/nsFileSpecUnix.cpp index dd6a4e85c66..bb9c73321af 100644 --- a/mozilla/xpcom/io/nsFileSpecUnix.cpp +++ b/mozilla/xpcom/io/nsFileSpecUnix.cpp @@ -232,6 +232,51 @@ void nsFileSpec::Delete(PRBool inRecursive) const remove(mPath); } // nsFileSpec::Delete +//---------------------------------------------------------------------------------------- +void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const +//---------------------------------------------------------------------------------------- +{ + if (IsDirectory()) + { + if (!(newDir.Exists())) + { + newDir.CreateDirectory(); + } + + for (nsDirectoryIterator i(*this); i.Exists(); i++) + { + nsFileSpec& child = (nsFileSpec&)i; + + if (child.IsDirectory()) + { + nsFileSpec tmpDirSpec(newDir); + + char *leafname = child.GetLeafName(); + tmpDirSpec += leafname; + nsCRT::free(leafname); + + child.RecursiveCopy(tmpDirSpec); + } + else + { + child.RecursiveCopy(newDir); + } + } + } + else if (!mPath.IsEmpty()) + { + nsFileSpec& filePath = (nsFileSpec&) *this; + + if (!(newDir.Exists())) + { + newDir.CreateDirectory(); + } + + filePath.Copy(newDir); + } +} // nsFileSpec::RecursiveCopy + + //---------------------------------------------------------------------------------------- nsresult nsFileSpec::Rename(const char* inNewName) //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsFileSpecWin.cpp b/mozilla/xpcom/io/nsFileSpecWin.cpp index 7c8a70568ff..a3d131009ab 100644 --- a/mozilla/xpcom/io/nsFileSpecWin.cpp +++ b/mozilla/xpcom/io/nsFileSpecWin.cpp @@ -282,6 +282,50 @@ void nsFileSpec::Delete(PRBool inRecursive) const } // nsFileSpec::Delete +//---------------------------------------------------------------------------------------- +void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const +//---------------------------------------------------------------------------------------- +{ + if (IsDirectory()) + { + if (!(newDir.Exists())) + { + newDir.CreateDirectory(); + } + + for (nsDirectoryIterator i(*this); i.Exists(); i++) + { + nsFileSpec& child = (nsFileSpec&)i; + + if (child.IsDirectory()) + { + nsFileSpec tmpDirSpec(newDir); + + char *leafname = child.GetLeafName(); + tmpDirSpec += leafname; + nsCRT::free(leafname); + + child.RecursiveCopy(tmpDirSpec); + } + else + { + child.RecursiveCopy(newDir); + } + } + } + else if (!mPath.IsEmpty()) + { + nsFileSpec& filePath = (nsFileSpec&) *this; + + if (!(newDir.Exists())) + { + newDir.CreateDirectory(); + } + + filePath.Copy(newDir); + } +} // nsFileSpec::RecursiveCopy + //---------------------------------------------------------------------------------------- nsresult nsFileSpec::Rename(const char* inNewName) //----------------------------------------------------------------------------------------