Enhanced fgfs-tools-client to eliminate some cases in which a tile does not
have to be rebuilt.
This commit is contained in:
parent
e62ee35e9b
commit
5eff254dc9
1 changed files with 80 additions and 13 deletions
|
@ -17,12 +17,14 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <utmp.h>
|
#include <utmp.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h> // atoi()
|
#include <stdlib.h> // atoi()
|
||||||
#include <string.h> // bcopy()
|
#include <string.h> // bcopy(), sterror()
|
||||||
#include <strings.h> // bcopy() on Irix
|
#include <strings.h> // bcopy() on Irix
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
@ -34,6 +36,7 @@
|
||||||
#include <simgear/bucket/newbucket.hxx>
|
#include <simgear/bucket/newbucket.hxx>
|
||||||
|
|
||||||
SG_USING_STD(cout);
|
SG_USING_STD(cout);
|
||||||
|
SG_USING_STD(cerr);
|
||||||
SG_USING_STD(endl);
|
SG_USING_STD(endl);
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,14 +180,12 @@ long int get_next_task( const string& host, int port, long int last_tile ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool file_exists( const string& file ) {
|
bool endswith(const char* s, const char* suffix) {
|
||||||
struct stat buf;
|
size_t slen=strlen(s);
|
||||||
|
size_t sufflen=strlen(suffix);
|
||||||
if ( stat( file.c_str(), &buf ) == 0 ) {
|
if (slen<sufflen)
|
||||||
return true;
|
return false;
|
||||||
} else {
|
return (strncmp(s+slen-sufflen,suffix,sufflen)==0);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the tile really has to be generated
|
// check if the tile really has to be generated
|
||||||
|
@ -194,11 +195,72 @@ static bool must_generate( const SGBucket& b ) {
|
||||||
|
|
||||||
string btg_file = output_base + "/" + b.gen_base_path()
|
string btg_file = output_base + "/" + b.gen_base_path()
|
||||||
+ "/" + b.gen_index_str() + ".btg.gz";
|
+ "/" + b.gen_index_str() + ".btg.gz";
|
||||||
if ( file_exists( btg_file ) ) {
|
string stg_file = output_base + "/" + b.gen_base_path()
|
||||||
return false;
|
+ "/" + b.gen_index_str() + ".stg";
|
||||||
|
struct stat btg_stat, stg_stat;
|
||||||
|
bool have_btg, have_stg;
|
||||||
|
|
||||||
|
have_btg= ( stat( btg_file.c_str(), &btg_stat ) == 0 );
|
||||||
|
have_stg = ( stat( stg_file.c_str(), &stg_stat ) == 0 );
|
||||||
|
|
||||||
|
if ( !have_btg ) {
|
||||||
|
cout << "Output file " << btg_file << " was not found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
if ( !have_stg ) {
|
||||||
|
cout << "Output file " << stg_file << " was not found\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now check the load dirs for any source data and
|
||||||
|
* whether any of that is newer than the btg-file or the stg-file
|
||||||
|
*/
|
||||||
|
const string& prefix=b.gen_index_str()+".";
|
||||||
|
size_t prefix_len=prefix.size();
|
||||||
|
for (int i = 0; i < (int)load_dirs.size(); i++) {
|
||||||
|
string path=load_dirs[i]+"/"+b.gen_base_path();
|
||||||
|
DIR *loaddir=opendir(path.c_str());
|
||||||
|
if (!loaddir) {
|
||||||
|
if (errno!=ENOENT)
|
||||||
|
cout << " Could not open load directory " << path << ":" << strerror(errno) << "\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent* de;
|
||||||
|
struct stat src_stat;
|
||||||
|
|
||||||
|
while ((de=readdir(loaddir))) {
|
||||||
|
if (strncmp(de->d_name,prefix.c_str(),prefix_len))
|
||||||
|
continue;
|
||||||
|
string file=path+"/"+de->d_name;
|
||||||
|
if ( stat(file.c_str(), &src_stat) != 0) {
|
||||||
|
/* huh!? */
|
||||||
|
cerr << " Could not stat file " << file << ":" << strerror(errno) << "\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( have_btg && src_stat.st_mtime>btg_stat.st_mtime ) {
|
||||||
|
cout << " File " << file << " is newer than btg-file => rebuild\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( have_stg && src_stat.st_mtime>stg_stat.st_mtime ) {
|
||||||
|
cout << " File " << file << " is newer than stg-file => rebuild\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/* Ignore elevation data, as it is not used if we have no
|
||||||
|
* landmass data. So in addition to elevation data we need at
|
||||||
|
* least one polygon file.
|
||||||
|
*/
|
||||||
|
if ( endswith( de->d_name, ".arr.gz" ) || endswith( de->d_name, ".fit.gz" ) )
|
||||||
|
continue;
|
||||||
|
if ( !(have_stg && have_btg) ) {
|
||||||
|
cout << " There is source-data (" << file << ") for tile " << b.gen_index_str() << " but .btg or .stg is missing => build\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(loaddir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -301,6 +363,10 @@ int main(int argc, char *argv[]) {
|
||||||
cout << "Running in rude mode" << endl;
|
cout << "Running in rude mode" << endl;
|
||||||
else
|
else
|
||||||
cout << "Running in polite mode" << endl;
|
cout << "Running in polite mode" << endl;
|
||||||
|
if (do_overwrite)
|
||||||
|
cout << "Will overwrite existing buckets" << endl;
|
||||||
|
else
|
||||||
|
cout << "Will not overwrite up-to-date existing buckets" << endl;
|
||||||
for (int i = arg_pos; i < argc; i++) {
|
for (int i = arg_pos; i < argc; i++) {
|
||||||
string dir;
|
string dir;
|
||||||
dir = work_base + "/";
|
dir = work_base + "/";
|
||||||
|
@ -334,6 +400,7 @@ int main(int argc, char *argv[]) {
|
||||||
if ( result ) {
|
if ( result ) {
|
||||||
last_tile = tile;
|
last_tile = tile;
|
||||||
} else {
|
} else {
|
||||||
|
cout << "Build of tile " << tile << " failed\n";
|
||||||
last_tile = -tile;
|
last_tile = -tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue