mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
added mvBak() to POSIX
- Rename to a corresponding backup file If the backup file already exists, attempt with "01" .. "99" suffix. - git ignore indexed backup files too
This commit is contained in:
13
.gitignore
vendored
13
.gitignore
vendored
@ -4,9 +4,13 @@
|
|||||||
# editor and misc backup files - anywhere
|
# editor and misc backup files - anywhere
|
||||||
*~
|
*~
|
||||||
.*~
|
.*~
|
||||||
*.orig
|
|
||||||
*.bak
|
*.bak
|
||||||
|
*.bak[0-9][0-9]
|
||||||
|
*.orig
|
||||||
|
*.orig[0-9][0-9]
|
||||||
\#*\#
|
\#*\#
|
||||||
|
|
||||||
|
# file-browser settings - anywhere
|
||||||
.directory
|
.directory
|
||||||
|
|
||||||
# CVS recovered versions - anywhere
|
# CVS recovered versions - anywhere
|
||||||
@ -18,7 +22,7 @@
|
|||||||
*.so
|
*.so
|
||||||
*.jar
|
*.jar
|
||||||
|
|
||||||
# ignore derived files
|
# derived files
|
||||||
lex.yy.c
|
lex.yy.c
|
||||||
|
|
||||||
# Corefiles
|
# Corefiles
|
||||||
@ -30,7 +34,7 @@ core
|
|||||||
# lnInclude (symlink) folders - anywhere
|
# lnInclude (symlink) folders - anywhere
|
||||||
lnInclude
|
lnInclude
|
||||||
|
|
||||||
# build folder(s) - anywhere
|
# build folders - anywhere
|
||||||
linux*Gcc*/
|
linux*Gcc*/
|
||||||
linux*Icc*/
|
linux*Icc*/
|
||||||
linuxming*/
|
linuxming*/
|
||||||
@ -38,9 +42,6 @@ SiCortex*Gcc*/
|
|||||||
solaris*Gcc*/
|
solaris*Gcc*/
|
||||||
SunOS*Gcc*/
|
SunOS*Gcc*/
|
||||||
|
|
||||||
# all of the wmake wmkdep and dirToString binaries
|
|
||||||
wmake/bin
|
|
||||||
|
|
||||||
# doxygen generated documentation
|
# doxygen generated documentation
|
||||||
doc/[Dd]oxygen/html
|
doc/[Dd]oxygen/html
|
||||||
doc/[Dd]oxygen/latex
|
doc/[Dd]oxygen/latex
|
||||||
|
|||||||
3
applications/test/mvBak/Make/files
Normal file
3
applications/test/mvBak/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
mvBakTest.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/mvBakTest
|
||||||
2
applications/test/mvBak/Make/options
Normal file
2
applications/test/mvBak/Make/options
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
|
||||||
|
/* EXE_LIBS = -lfiniteVolume */
|
||||||
81
applications/test/mvBak/mvBakTest.C
Normal file
81
applications/test/mvBak/mvBakTest.C
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Description
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "OSspecific.H"
|
||||||
|
#include "argList.H"
|
||||||
|
|
||||||
|
using namespace Foam;
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// Main program:
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
argList::noBanner();
|
||||||
|
argList::noParallel();
|
||||||
|
argList::validArgs.insert("file .. fileN");
|
||||||
|
argList::validOptions.erase("case");
|
||||||
|
argList::validOptions.insert("ext", "bak");
|
||||||
|
|
||||||
|
argList args(argc, argv, false, true);
|
||||||
|
|
||||||
|
if (args.additionalArgs().empty())
|
||||||
|
{
|
||||||
|
args.printUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
label ok = 0;
|
||||||
|
|
||||||
|
forAll(args.additionalArgs(), argI)
|
||||||
|
{
|
||||||
|
const string& srcFile = args.additionalArgs()[argI];
|
||||||
|
|
||||||
|
if (args.optionFound("ext"))
|
||||||
|
{
|
||||||
|
if (mvBak(srcFile, args.option("ext")))
|
||||||
|
{
|
||||||
|
ok++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mvBak(srcFile))
|
||||||
|
{
|
||||||
|
ok++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "mvBak called for " << args.additionalArgs().size()
|
||||||
|
<< " files (moved " << ok << ")\n" << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -781,6 +781,45 @@ bool Foam::mv(const fileName& src, const fileName& dst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Rename to a corresponding backup file
|
||||||
|
// If the backup file already exists, attempt with "01" .. "99" index
|
||||||
|
bool Foam::mvBak(const fileName& src, const std::string& ext)
|
||||||
|
{
|
||||||
|
if (POSIX::debug)
|
||||||
|
{
|
||||||
|
Info<< "mvBak : " << src << " to extension " << ext << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists(src, false))
|
||||||
|
{
|
||||||
|
const int maxIndex = 99;
|
||||||
|
char index[3];
|
||||||
|
|
||||||
|
for (int n = 0; n <= maxIndex; n++)
|
||||||
|
{
|
||||||
|
fileName dstName(src + "." + ext);
|
||||||
|
if (n)
|
||||||
|
{
|
||||||
|
sprintf(index, "%02d", n);
|
||||||
|
dstName += index;
|
||||||
|
}
|
||||||
|
|
||||||
|
// avoid overwriting existing files, except for the last
|
||||||
|
// possible index where we have no choice
|
||||||
|
if (!exists(dstName, false) || n == maxIndex)
|
||||||
|
{
|
||||||
|
return rename(src.c_str(), dstName.c_str()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fall-through: nothing to do
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Remove a file, returning true if successful otherwise false
|
// Remove a file, returning true if successful otherwise false
|
||||||
bool Foam::rm(const fileName& file)
|
bool Foam::rm(const fileName& file)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -144,15 +144,19 @@ fileNameList readDir
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Copy, recursively if necessary, the source to the destination
|
//- Copy, recursively if necessary, the source to the destination
|
||||||
bool cp(const fileName& srcFile, const fileName& destFile);
|
bool cp(const fileName& src, const fileName& dst);
|
||||||
|
|
||||||
//- Create a softlink. destFile should not exist. Returns true if successful.
|
//- Create a softlink. dst should not exist. Returns true if successful.
|
||||||
bool ln(const fileName& srcFile, const fileName& destFile);
|
bool ln(const fileName& src, const fileName& dst);
|
||||||
|
|
||||||
//- Rename srcFile destFile
|
//- Rename src to dst
|
||||||
bool mv(const fileName& srcFile, const fileName& destFile);
|
bool mv(const fileName& src, const fileName& dst);
|
||||||
|
|
||||||
//- Remove a file returning true if successful otherwise false
|
//- Rename to a corresponding backup file
|
||||||
|
// If the backup file already exists, attempt with "01" .. "99" suffix
|
||||||
|
bool mvBak(const fileName&, const std::string& ext = "bak");
|
||||||
|
|
||||||
|
//- Remove a file, returning true if successful otherwise false
|
||||||
bool rm(const fileName&);
|
bool rm(const fileName&);
|
||||||
|
|
||||||
//- Remove a dirctory and its contents
|
//- Remove a dirctory and its contents
|
||||||
|
|||||||
Reference in New Issue
Block a user