Skip to content
Snippets Groups Projects
Commit 00a4ee95 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

PLUMED_MAXBACKUP environment variable

Allows to switch off auto backup or to change the maximum number of 
backups
parent d6fe1049
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <cstdlib>
namespace PLMD{ namespace PLMD{
...@@ -221,7 +222,9 @@ OFile& OFile::open(const std::string&path){ ...@@ -221,7 +222,9 @@ OFile& OFile::open(const std::string&path){
if(plumed && plumed->getRestart()){ if(plumed && plumed->getRestart()){
fp=std::fopen(const_cast<char*>(this->path.c_str()),"a"); fp=std::fopen(const_cast<char*>(this->path.c_str()),"a");
} else { } else {
if(!comm || comm->Get_rank()==0){ int maxbackup=100;
if(std::getenv("PLUMED_MAXBACKUP")) Tools::convert(std::getenv("PLUMED_MAXBACKUP"),maxbackup);
if(maxbackup>0 && (!comm || comm->Get_rank()==0)){
FILE* ff=std::fopen(const_cast<char*>(this->path.c_str()),"r"); FILE* ff=std::fopen(const_cast<char*>(this->path.c_str()),"r");
FILE* fff=NULL; FILE* fff=NULL;
if(ff){ if(ff){
...@@ -232,6 +235,7 @@ OFile& OFile::open(const std::string&path){ ...@@ -232,6 +235,7 @@ OFile& OFile::open(const std::string&path){
for(int i=0;;i++){ for(int i=0;;i++){
std::string num; std::string num;
Tools::convert(i,num); Tools::convert(i,num);
if(i>maxbackup) plumed_merror("cannot backup file "+file+" maximum number of backup is "+num+"\n");
backup=directory+"bck."+num+"."+file; backup=directory+"bck."+num+"."+file;
fff=std::fopen(backup.c_str(),"r"); fff=std::fopen(backup.c_str(),"r");
if(!fff) break; if(!fff) break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment