diff options
author | 2010-07-04 21:43:21 +0300 | |
---|---|---|
committer | 2010-07-04 21:43:21 +0300 | |
commit | 2fea43a56b16c18ba4c9d1934b8bb2f78e80c51d (patch) | |
tree | 671bd5157be74fa874b4c2e9fde04fec07e062c1 | |
parent | Add option [provide_mirror_to_others].provide_mirror_dir (diff) | |
download | idfetch-2fea43a56b16c18ba4c9d1934b8bb2f78e80c51d.tar.gz idfetch-2fea43a56b16c18ba4c9d1934b8bb2f78e80c51d.tar.bz2 idfetch-2fea43a56b16c18ba4c9d1934b8bb2f78e80c51d.zip |
Add option [provide_mirror_to_others].provide_mirror_files_restrict_list_on to segget.conf file
SYNOPSIS: PROVIDE_MIRROR_FILES_RESTRICT_LIST_ON= 0 | 1
If PROVIDE_MIRROR_DIR=none this option will be ignored.
- If set to 1, segget will compare distfile name with the list of forbiden
patterns from the restricted.conf file. If distfile name contains any of the
patterns, no symlink will be provided to this distfile.
Default:
provide_mirror_files_restrict_list_on=0
-rw-r--r-- | segget/distfile.cpp | 12 | ||||
-rw-r--r-- | segget/restrict.conf | 2 | ||||
-rw-r--r-- | segget/segget.conf | 17 | ||||
-rw-r--r-- | segget/settings.cpp | 39 | ||||
-rw-r--r-- | segget/settings.h | 7 |
5 files changed, 71 insertions, 6 deletions
diff --git a/segget/distfile.cpp b/segget/distfile.cpp index 04f1fd4..7e637c6 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -282,6 +282,14 @@ void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){ } } void Tdistfile::symlink_distfile_to_provide_mirror_dir(){ + for(ulong pattern_num=0; pattern_num<settings.provide_mirror_files_restricted_patterns_vector.size(); pattern_num++){ + if (name.find(settings.provide_mirror_files_restricted_patterns_vector[pattern_num],0)!=name.npos){ + log("Symlink to distfile:"+name+" was restricted by pattern <" + +settings.provide_mirror_files_restricted_patterns_vector[pattern_num] + +"> from line "+toString(pattern_num+1)+" of restrict.conf file"); + return; + } + } string new_mirror_name; string old_distfile_name; try{ @@ -426,7 +434,9 @@ int Tdistfile::combine_segments(){ error_log("Error: SHA256 checksum for distfile:"+name+" [FAILED]"); return 12; } - symlink_distfile_to_provide_mirror_dir(); + if (settings.provide_mirror_dir!="none"){ + symlink_distfile_to_provide_mirror_dir(); + } }catch(...){ error_log("Error: distfile.cpp: combine_segments() for segment:"+settings.distfiles_dir+"/"+name+" while checking checksums."); return 30; diff --git a/segget/restrict.conf b/segget/restrict.conf new file mode 100644 index 0000000..e554a5b --- /dev/null +++ b/segget/restrict.conf @@ -0,0 +1,2 @@ +libX +bz2
\ No newline at end of file diff --git a/segget/segget.conf b/segget/segget.conf index 901f8d9..71c37f4 100644 --- a/segget/segget.conf +++ b/segget/segget.conf @@ -157,12 +157,23 @@ use_benchmark_stats=1 benchmark_oblivion=5 [provide_mirror_to_others] -# MIRROR_DIR -# Define a dir to store distfiles for mirroring. +# PROVIDE_MIRROR_DIR +# Define a dir for making symlinks to downloaded distfiles. This dir can be +# used to provide local mirror for other hosts (with help of Apache, vsftp, etc). +# If set to none, segget will not make symlinks. # Default: -# provide_mirror_dir=./provide_mirror_dir +# provide_mirror_dir=none provide_mirror_dir=./provide_mirror_dir +# SYNOPSIS: PROVIDE_MIRROR_FILES_RESTRICT_LIST_ON= 0 | 1 +# If PROVIDE_MIRROR_DIR=none this option will be ignored. +# - If set to 1, segget will compare distfile name with the list of forbiden +# patterns from the restricted.conf file. If distfile name contains any of the +# patterns, no symlink will be provided to this distfile. +# Default: +# provide_mirror_files_restrict_list_on=0 +provide_mirror_files_restrict_list_on=1 + [networks] # NETWORK0_PRIORITY # Define priority as a value in range from lowest 0 to highest 10. diff --git a/segget/settings.cpp b/segget/settings.cpp index 49cc568..352f19b 100644 --- a/segget/settings.cpp +++ b/segget/settings.cpp @@ -25,6 +25,38 @@ */ #include "settings.h" +void Tsettings::load_provide_mirror_files_restricted_patterns_vector(){ + ifstream file; + file.exceptions (ifstream::failbit | ifstream::badbit); + try{ + file.open("restrict.conf"); + } + catch(...){ + error_log("Can NOT open pattern list file restrict.conf. Setting provide_mirror_files_restrict_list_on=0 will be forced."); + provide_mirror_files_restrict_list_on=0; + return; + } + try{ + //processing file + string restricted_pattern_line; + while (not(file.eof())) { + getline(file,restricted_pattern_line); + if (! restricted_pattern_line.length()) continue; + if (restricted_pattern_line[0] == '#') continue; + if (restricted_pattern_line[0] == ';') continue; + provide_mirror_files_restricted_patterns_vector.push_back(restricted_pattern_line); + debug("restricted_pattern_line added:"+restricted_pattern_line); + } + log(toString(provide_mirror_files_restricted_patterns_vector.size())+" pattern(s) was(were) read from restrict.conf"); + if (! provide_mirror_files_restricted_patterns_vector.size()){ + error_log("No patterns were read from restrict.conf file. Setting provide_mirror_files_restrict_list_on=0 will be forced."); + provide_mirror_files_restrict_list_on=0; + } + } + catch(...){ + error_log("Restricted pattern list file restrict.conf was opened, but an error occured while reading it."); + } +} void Tsettings::init(){ try{ @@ -52,7 +84,12 @@ void Tsettings::init(){ conf.set(max_connections_num_per_mirror, "mirrors", "max_connections_num_per_mirror",1,10); conf.set(benchmark_oblivion, "mirrors", "benchmark_oblivion",0,1000); - conf.set(provide_mirror_dir, "provide_mirror_to_others", "provide_mirror_dir"); + conf.set(provide_mirror_dir, "provide_mirror_to_others", "provide_mirror_dir"); + if (provide_mirror_dir!="none"){ + conf.set(provide_mirror_files_restrict_list_on, "provide_mirror_to_others", "provide_mirror_files_restrict_list_on"); + if (provide_mirror_files_restrict_list_on) + load_provide_mirror_files_restricted_patterns_vector(); + } ulong cur_network_priority; for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){ diff --git a/segget/settings.h b/segget/settings.h index cb96de8..c746888 100644 --- a/segget/settings.h +++ b/segget/settings.h @@ -37,6 +37,7 @@ using namespace std; class Tsettings{ private: + void load_provide_mirror_files_restricted_patterns_vector(); public: //folders string distfiles_dir; @@ -65,6 +66,8 @@ class Tsettings{ ulong benchmark_oblivion; //provide_mirror_to_others string provide_mirror_dir; + bool provide_mirror_files_restrict_list_on; + vector<string> provide_mirror_files_restricted_patterns_vector; //logs string logs_dir; string general_log_file; @@ -98,7 +101,9 @@ class Tsettings{ max_connections_num_per_mirror(1), benchmark_oblivion(5), //provide_mirror_to_others - provide_mirror_dir("./provide_mirror_dir"), + provide_mirror_dir("none"), + provide_mirror_files_restrict_list_on(0), + provide_mirror_files_restricted_patterns_vector(), //logs logs_dir("./logs"), general_log_file("segget.log"), |