summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-10 11:05:28 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-10 11:05:28 +0300
commit7001eaeb94bf3365ded35910598f1e6a66c345fa (patch)
treec8b4ed0014ee783270f58adf70eb9fa690b98456
parentReplace <meta http-equiv=\"refresh\" content=\"1\" > in WebUI by XMLHttpReque... (diff)
downloadidfetch-7001eaeb94bf3365ded35910598f1e6a66c345fa.tar.gz
idfetch-7001eaeb94bf3365ded35910598f1e6a66c345fa.tar.bz2
idfetch-7001eaeb94bf3365ded35910598f1e6a66c345fa.zip
Replace default folders.
distfiles_dir=/usr/portage/distfiles segments_dir=/tmp/seggetd/segments scripts_dir=/usr/share/seggetd/scripts logs_dir=/var/log/seggetd
-rw-r--r--segget/connection.cpp16
-rw-r--r--segget/distfile.cpp9
-rw-r--r--segget/log.cpp16
-rw-r--r--segget/response.h5
-rw-r--r--segget/segget.cpp3
-rw-r--r--segget/segget.h2
-rw-r--r--segget/segment.cpp32
-rw-r--r--segget/segment.h4
-rw-r--r--segget/settings.cpp4
-rw-r--r--segget/settings.h18
-rw-r--r--segget/stats.cpp12
11 files changed, 77 insertions, 44 deletions
diff --git a/segget/connection.cpp b/segget/connection.cpp
index 108a98b..88f6069 100644
--- a/segget/connection.cpp
+++ b/segget/connection.cpp
@@ -79,14 +79,16 @@ int Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegme
}
return REJECTED_BY_USER_PYTHON_SCRIPT;
}
-
- segment->parent_distfile->active_connections_num++;
- active=true;
- Pcurr_mirror->start();
- network_array[network_num].connect();
-
stats.active_connections_counter++;
- segment->prepare_for_connection(cm, connection_num, network_num, distfile_num, url);
+ ulong segment_start_result=segment->start(cm, connection_num, network_num, distfile_num, url);
+ if (segment_start_result){
+ return segment_start_result;
+ }else{
+ segment->parent_distfile->active_connections_num++;
+ active=true;
+ Pcurr_mirror->start();
+ network_array[network_num].connect();
+ }
debug("Started connection for distfile: "+segment->parent_distfile->name);
return 0;
}catch(...){
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index 2245616..b48e50d 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -861,12 +861,17 @@ int Tdistfile::combine_segments(){
try{
debug("Combining distfile"+name);
ofstream distfile_file;
- distfile_file.exceptions (ofstream::failbit | ofstream::badbit);
+ distfile_file.exceptions (ofstream::badbit);
string distfile_path=settings.distfiles_dir+"/"+name;
try{
distfile_file.open(distfile_path.c_str(),ofstream::binary|ios::trunc);
+ if (distfile_file==0){
+ error_log("Error: distfile.cpp: combine_segments(): opening distfile "+distfile_path+" for writing");
+ error_log("....Check if folder "+settings.distfiles_dir+" exists and seggetd has permissions to write into it.");
+ }
}catch(...){
- error_log("Error: distfile.cpp: combine_segments(): opening distfile:"+distfile_path);
+ error_log("Error: distfile.cpp: combine_segments(): opening distfile "+distfile_path+" for writing");
+ error_log("....Check if folder "+settings.distfiles_dir+" exists and seggetd has permissions to write into it.");
status=DFAILED;
return 1;
}
diff --git a/segget/log.cpp b/segget/log.cpp
index b1a3648..d19876d 100644
--- a/segget/log.cpp
+++ b/segget/log.cpp
@@ -55,8 +55,14 @@ void log_no_msg(string log_msg_text){
file.exceptions (ofstream::failbit | ofstream::badbit);
try{
file.open((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app);
+ if (file==0){
+ error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+" for writing.");
+ error_log("....Check if folder "+settings.logs_dir+" exists and seggetd has rights to write into it.");
+ return;
+ }
}catch(...){
- error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+".");
+ error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+" for writing.");
+ error_log("....Check if folder "+settings.logs_dir+" exists and seggetd has rights to write into it.");
return;
}
try{
@@ -111,9 +117,15 @@ void debug_no_msg(string debug_msg_text){
file.exceptions (ofstream::failbit | ofstream::badbit);
try{
file.open((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app);
+ if (file==0){
+ error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+" for writing.");
+ error_log("....Check if folder "+settings.logs_dir+" exists and seggetd has permissions to write into it.");
+ return;
+ }
}
catch(...){
- error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+".");
+ error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+" for writing.");
+ error_log("....Check if folder "+settings.logs_dir+" exists and seggetd has permissions to write into it.");
return;
}
try{
diff --git a/segget/response.h b/segget/response.h
index d78bc7c..b24645b 100644
--- a/segget/response.h
+++ b/segget/response.h
@@ -59,6 +59,11 @@ using namespace std;
#define REJECTED_BY_USER_PYTHON_SCRIPT 301
#define ERROR_WHILE_PREPARING_CONNECTION 302
+#define ERROR_DURING_SEGMENT_START 400
+
+#define ERROR_WHILE_OPENING_SEGMENT_FOR_WRITING 500
+#define ERROR_ADDING_EASY_HANDLE_TO_MULTI 501
+
int decode_server_response(string server_response);
#endif \ No newline at end of file
diff --git a/segget/segget.cpp b/segget/segget.cpp
index d13d731..409bf9f 100644
--- a/segget/segget.cpp
+++ b/segget/segget.cpp
@@ -25,7 +25,7 @@
*/
#include "segget.h"
-
+/*
int load_pkgs(){
try{
@@ -79,6 +79,7 @@ int load_pkgs(){
return 1;
}
}
+*/
/*
void show_pkgs(){
try{
diff --git a/segget/segget.h b/segget/segget.h
index b74c458..cada6f1 100644
--- a/segget/segget.h
+++ b/segget/segget.h
@@ -66,7 +66,7 @@ int routine();
void start_daemon_mode();
int parse_cli_arguments(int argc, char* argv[]);
int init_curses();
-int load_pkgs();
+//int load_pkgs();
void show_pkgs();
int pkg_choose_segment(Tpkg * cur_pkg, uint connection_num);
int choose_segment(uint connection_num);
diff --git a/segget/segment.cpp b/segget/segment.cpp
index 82be817..cc4e2f2 100644
--- a/segget/segment.cpp
+++ b/segget/segment.cpp
@@ -78,7 +78,7 @@ void Tsegment::set_segment(Tdistfile *prnt_distfile, uint seg_num, string distfi
error_log("Error in segment.cpp: prepare_for_connection()");
}
}
-void Tsegment::prepare_for_connection(CURLM *cm, uint con_num, uint network_num, uint distfile_num, string url_address){
+uint Tsegment::start(CURLM *cm, uint con_num, uint network_num, uint distfile_num, string url_address){
try{
// debug("NETWORK:"+toString(network_num)+(network_array[network_num].use_own_mirror_list_only_on ? " - LOCAL": " - REMOTE"));
// if MODE_LOCAL or MODE_PROXY_FETCHER
@@ -90,9 +90,10 @@ void Tsegment::prepare_for_connection(CURLM *cm, uint con_num, uint network_num,
connection_num=con_num;
// connection_array[con_num].start(network_num);
try_num++;
- add_easy_handle_to_multi(cm, network_num);
+ return add_easy_handle_to_multi(cm, network_num);
}catch(...){
error_log("Error in segment.cpp: prepare_for_connection()");
+ return ERROR_DURING_SEGMENT_START;
}
}
@@ -104,18 +105,25 @@ Tsegment::~Tsegment(){
}
}
-int Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){
+uint Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){
try{
segment_file.exceptions (ofstream::badbit);
segment_file.open((settings.segments_dir+"/"+file_name).c_str(), ios::trunc|ios::binary );
- }catch(std::ifstream::failure e){
- if (!segment_file.eof()){
- error_log("Can't open segment file:"+settings.segments_dir+"/"+file_name+": "+(string)e.what());
- return 1;
- }
+ if (segment_file==0){
+ error_log("Can't open for writing segment file "+settings.segments_dir+"/"+file_name);
+ error_log("....Check if folder "+settings.segments_dir+" exists and seggetd has permisions to write into it");
+ return ERROR_WHILE_OPENING_SEGMENT_FOR_WRITING;
+ }
+ }catch(ifstream::failure e){
+ if (!segment_file.eof()){
+ error_log("Can't open for writing segment file: "+settings.segments_dir+"/"+file_name+": "+(string)e.what());
+ error_log("....Check if folder "+settings.segments_dir+" exists and seggetd has permisions to write into it");
+ return ERROR_WHILE_OPENING_SEGMENT_FOR_WRITING;
+ }
}catch(...){
- error_log("Unknown error: Can't open segment file:"+settings.segments_dir+"/"+file_name);
- return 1;
+ error_log("Unknown error: Can't open for writing segment file: "+settings.segments_dir+"/"+file_name);
+ error_log("Check if folder "+settings.segments_dir+" exists and seggetd has permisions to write into this folder");
+ return ERROR_WHILE_OPENING_SEGMENT_FOR_WRITING;
}
try{
easyhandle = curl_easy_init();
@@ -174,10 +182,10 @@ int Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){
curl_multi_add_handle(cm, easyhandle);
return 0;
}else
- return 1;
+ return ERROR_ADDING_EASY_HANDLE_TO_MULTI;
}catch(...){
error_log("Error in segment.cpp: add_easy_handle_to_multi()");
- return 1;
+ return ERROR_ADDING_EASY_HANDLE_TO_MULTI;
}
}
void show_progress(double time_diff){
diff --git a/segget/segment.h b/segget/segment.h
index b63e8e6..d64d088 100644
--- a/segget/segment.h
+++ b/segget/segment.h
@@ -87,9 +87,9 @@ class Tsegment{
~Tsegment();
bool segment_verification_is_ok();
void set_segment(Tdistfile *prnt_distfile, uint seg_num, string distfile_name, ulong default_seg_size, ulong range_end);
- void prepare_for_connection(CURLM *cm, uint con_num, uint network_num, uint distfile_num, string url);
string get_file_name(){return file_name;};
- int add_easy_handle_to_multi(CURLM *cm, uint network_num);
+ uint start(CURLM *cm, uint con_num, uint network_num, uint distfile_num, string url);
+ uint add_easy_handle_to_multi(CURLM *cm, uint network_num);
};
extern Tsegment *segments_in_progress[MAX_CONNECTS];
diff --git a/segget/settings.cpp b/segget/settings.cpp
index 8637261..69c3d1d 100644
--- a/segget/settings.cpp
+++ b/segget/settings.cpp
@@ -81,8 +81,8 @@ void Tsettings::init(){
conf.set("folders","distfiles_dir",distfiles_dir);
conf.set("folders","segments_dir",segments_dir);
- conf.set("pkg_list","pkg_list_dir",pkg_list_dir);
- conf.set("pkg_list","del_pkg_list_when_dld_finished",del_pkg_list_when_dld_finished);
+// conf.set("pkg_list","pkg_list_dir",pkg_list_dir);
+// conf.set("pkg_list","del_pkg_list_when_dld_finished",del_pkg_list_when_dld_finished);
conf.set("distfiles","max_connection_num_per_distfile",max_connection_num_per_distfile,1,MAX_CONNECTS);
diff --git a/segget/settings.h b/segget/settings.h
index dea56c8..5523f90 100644
--- a/segget/settings.h
+++ b/segget/settings.h
@@ -45,8 +45,8 @@ class Tsettings{
string distfiles_dir;
string segments_dir;
//pkg_list
- string pkg_list_dir;
- bool del_pkg_list_when_dld_finished;
+// string pkg_list_dir;
+// bool del_pkg_list_when_dld_finished;
//distfiles
ulong max_connection_num_per_distfile;
//segments
@@ -101,11 +101,11 @@ class Tsettings{
conf_dir("/etc/seggetd"),
no_daemon_flag(false),
//folders
- distfiles_dir("./distfiles"),
- segments_dir("./tmp"),
+ distfiles_dir("/usr/portage/distfiles"),
+ segments_dir("/tmp/seggetd/segments"),
//pkg_list
- pkg_list_dir("./"),
- del_pkg_list_when_dld_finished(1),
+// pkg_list_dir("./"),
+// del_pkg_list_when_dld_finished(1),
//distfiles
max_connection_num_per_distfile(3),
//segments
@@ -146,12 +146,12 @@ class Tsettings{
request_port(10000),
//scripting_and_scheduling
python_path("/usr/bin/python"),
- scripts_dir("./scripts"),
+ scripts_dir("/usr/share/seggetd/scripts"),
//logs
- logs_dir("./logs"),
+ logs_dir("/var/log/seggetd"),
general_log_file("segget.log"),
error_log_file("error.log"),
- debug_log_file("debug.log"),
+ debug_log_file("none"),
general_log_time_format("%m/%d %X"),
error_log_time_format("%m/%d %X"),
debug_log_time_format("%m/%d %X")
diff --git a/segget/stats.cpp b/segget/stats.cpp
index a49b589..7bff34e 100644
--- a/segget/stats.cpp
+++ b/segget/stats.cpp
@@ -31,13 +31,13 @@ Tstats stats;
void Tstats::inc_dld_distfiles_count(){
try{
dld_distfiles_count++;
- if ((settings.del_pkg_list_when_dld_finished) and (dld_distfiles_count>distfiles_count)){
+// if ((settings.del_pkg_list_when_dld_finished) and (dld_distfiles_count>distfiles_count)){
//delete pkg.list file;
- if(remove((settings.pkg_list_dir+"/pkg.list").c_str()) != 0 )
- error_log("Error in stats.cpp: inc_dld_distfiles_count(): Can't delete:"+settings.pkg_list_dir+"/pkg.list");
- else
- debug(settings.pkg_list_dir+"/pkg.list"+" deleted" );
- }
+// if(remove((settings.pkg_list_dir+"/pkg.list").c_str()) != 0 )
+// error_log("Error in stats.cpp: inc_dld_distfiles_count(): Can't delete:"+settings.pkg_list_dir+"/pkg.list");
+// else
+// debug(settings.pkg_list_dir+"/pkg.list"+" deleted" );
+// }
}catch(...){
error_log("Error in stats.cpp: show_totals()");
}