summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-04 19:24:47 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-04 19:24:47 +0300
commit520a5d234c937a2dbcaabc4872c5f57e47081ec7 (patch)
tree0ad80069687bed951a11fbd2f90cc0ba714813d9
parentMerge 2 vectors: network_array[network_num].mirror_list and network_array[net... (diff)
downloadidfetch-520a5d234c937a2dbcaabc4872c5f57e47081ec7.tar.gz
idfetch-520a5d234c937a2dbcaabc4872c5f57e47081ec7.tar.bz2
idfetch-520a5d234c937a2dbcaabc4872c5f57e47081ec7.zip
Add option [provide_mirror_to_others].provide_mirror_dir
[provide_mirror_to_others] PROVIDE_MIRROR_DIR Define a dir to store distfiles for mirroring. Default: provide_mirror_dir=./provide_mirror_dir
-rw-r--r--segget/distfile.cpp73
-rw-r--r--segget/distfile.h8
-rw-r--r--segget/network.cpp1
-rw-r--r--segget/network0.conf4
-rw-r--r--segget/network1.conf2
-rw-r--r--segget/provide_mirror_dir/.gitignore0
-rw-r--r--segget/segget.conf4
-rw-r--r--segget/settings.cpp2
-rw-r--r--segget/settings.h20
9 files changed, 85 insertions, 29 deletions
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index bfbbb77..04f1fd4 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -281,21 +281,77 @@ void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){
error_log("Error: distfile.cpp: inc_dld_segments_count()");
}
}
+void Tdistfile::symlink_distfile_to_provide_mirror_dir(){
+ string new_mirror_name;
+ string old_distfile_name;
+ try{
+ string old_distfile_path;
+ char current_path[FILENAME_MAX];
+ if (!GetCurrentDir(current_path, sizeof(current_path)))
+ {
+ return;
+ }
+ if (settings.distfiles_dir.find("./",0)==0){
+ old_distfile_path=current_path+settings.distfiles_dir.substr(1,settings.distfiles_dir.npos);
+ }else{
+ old_distfile_path=settings.distfiles_dir;
+ }
+ new_mirror_name=settings.provide_mirror_dir+"/"+name;
+ old_distfile_name=old_distfile_path+"/"+name;
+ try{
+ if (!symlink(old_distfile_name.c_str(), new_mirror_name.c_str())){
+ log("Distfile:"+old_distfile_path+" was symlinked to the mirror dir:");
+ };
+ }catch(uint errno){
+ switch (errno){
+ case EACCES : error_log("Write access to the directory containing "+settings.provide_mirror_dir+" is denied, or one of the directories in the path prefix of "+settings.provide_mirror_dir+" did not allow search permission. (See also path_resolution(7).");
+ break;
+ case EEXIST : error_log("There is already an existing file named "+new_mirror_name+".");
+ break;
+ case EFAULT : error_log(old_distfile_path+" or "+settings.provide_mirror_dir+" points outside your accessible address space.");
+ break;
+ case EIO : error_log("A hardware error occurred while reading or writing data on the disk.");
+ break;
+ case ELOOP : error_log("Too many symbolic links were encountered in resolving "+settings.provide_mirror_dir+".");
+ break;
+ case ENAMETOOLONG : error_log(old_distfile_path+" or "+settings.provide_mirror_dir+" was too long.");
+ break;
+ case ENOENT : error_log("A directory component in "+settings.provide_mirror_dir+" does not exist or is a dangling symbolic link, or "+old_distfile_path+" is the empty string.");
+ break;
+ case ENOMEM : error_log("Insufficient kernel memory was available.");
+ break;
+ case ENOSPC : error_log("The device containing the file has no room for the new directory entry.");
+ break;
+ case ENOTDIR : error_log("A component used as a directory in "+settings.provide_mirror_dir+" is not, in fact, a directory.");
+ break;
+ case EPERM : error_log("The file system containing "+settings.provide_mirror_dir+" does not support the creation of symbolic links.");
+ break;
+ case EROFS : error_log("The file "+new_mirror_name+" would exist on a read-only file system.");
+ break;
+ default:
+ error_log("Undocumented error while trying to symlink "+old_distfile_name+" to "+new_mirror_name);
+ }
+ }catch(...){
+ error_log("Undocumented error (error description is not an integer) while trying to symlink "+old_distfile_name+" to "+new_mirror_name);
+ }
+ }catch(...){
+ error_log("Error in distfile.cpp :: symlink_distfile_to_provide_mirror_dir() while trying to symlink "+old_distfile_name+" to "+new_mirror_name);
+ }
+}
int Tdistfile::combine_segments(){
try{
debug("Combining distfile"+name);
ofstream distfile_file;
distfile_file.exceptions (ofstream::failbit | ofstream::badbit);
+ string distfile_path=settings.distfiles_dir+"/"+name;
try{
- distfile_file.open((settings.distfiles_dir+"/"+name).c_str(),ofstream::binary|ios::trunc);
+ distfile_file.open(distfile_path.c_str(),ofstream::binary|ios::trunc);
}catch(...){
- error_log("Error: distfile.cpp: combine_segments(): opening distfile:"+settings.distfiles_dir+"/"+name);
+ error_log("Error: distfile.cpp: combine_segments(): opening distfile:"+distfile_path);
return 1;
}
char * buffer;
ulong cur_seg_size;
- // char * buffer;
- // buffer = new char [size];
try{
for (uint seg_num=0; seg_num < segments_count; seg_num++){
debug("Joining "+name+" segment "+toString(seg_num)+" ");
@@ -346,13 +402,13 @@ int Tdistfile::combine_segments(){
error_log("Error in distfile.cpp: combine_segments() for distfile:"+settings.distfiles_dir+"/"+name);
return 5;
}
-
try{
if (rmd160_ok(settings.distfiles_dir+"/"+name,RMD160))
log("RMD160 checksum for distfile:"+name+" is [OK]");
else{
log("Error: RMD160 checksum for distfile:"+name+" [FAILED]");
error_log("Error: RMD160 checksum for distfile:"+name+" [FAILED]");
+ return 10;
}
if (sha1_ok(settings.distfiles_dir+"/"+name,SHA1))
@@ -360,6 +416,7 @@ int Tdistfile::combine_segments(){
else{
log("Error: SHA1 checksum for distfile:"+name+" [FAILED]");
error_log("Error: SHA1 checksum for distfile:"+name+" [FAILED]");
+ return 11;
}
if (sha256_ok(settings.distfiles_dir+"/"+name,SHA256))
@@ -367,14 +424,16 @@ int Tdistfile::combine_segments(){
else{
log("Error: SHA256 checksum for distfile:"+name+" [FAILED]");
error_log("Error: SHA256 checksum for distfile:"+name+" [FAILED]");
+ return 12;
}
+ symlink_distfile_to_provide_mirror_dir();
}catch(...){
error_log("Error: distfile.cpp: combine_segments() for segment:"+settings.distfiles_dir+"/"+name+" while checking checksums.");
- return 6;
+ return 30;
}
}catch(...){
error_log("Error: distfile.cpp: combine_segments() for segment:"+settings.distfiles_dir+"/"+name+" during procedure.");
- return 7;
+ return 31;
}
return 0;
} \ No newline at end of file
diff --git a/segget/distfile.h b/segget/distfile.h
index b13ef9b..0768b32 100644
--- a/segget/distfile.h
+++ b/segget/distfile.h
@@ -39,6 +39,13 @@
#include <fstream>
#include <iostream>
#include <json/json.h>
+#ifdef WINDOWS
+ #include <direct.h>
+ #define GetCurrentDir _getcwd
+#else
+ #include <unistd.h>
+ #define GetCurrentDir getcwd
+#endif
#include "segment.h"
#include "mirror.h"
#include "checksum.cpp"
@@ -98,6 +105,7 @@ class Tdistfile{
void split_into_segments();
int provide_segment(CURLM* cm, uint connection_num, uint seg_num);
void inc_dld_segments_count(Tsegment * current_segment);
+ void symlink_distfile_to_provide_mirror_dir();
int combine_segments();
bool check_if_dld();
};
diff --git a/segget/network.cpp b/segget/network.cpp
index dbbcf47..bb58a2b 100644
--- a/segget/network.cpp
+++ b/segget/network.cpp
@@ -99,7 +99,6 @@ bool Tnetwork::has_free_connections(){
}
}
-
bool Tnetwork::connect(){
if (active_connections_num<max_connections){
active_connections_num++;
diff --git a/segget/network0.conf b/segget/network0.conf
index aabc4c2..2fc7aea 100644
--- a/segget/network0.conf
+++ b/segget/network0.conf
@@ -183,10 +183,10 @@ use_own_mirror_list_only_on=0
# SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1
# If NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 this option will be ignored.
# - If set to 1, segget will not use remote mirrors with equal or lower priority
-# untill all mirrors in network0_mirrors.conf file have failed.
+# until all mirrors in network0_mirrors.conf file have failed.
# - If set to 0, segget will use remote mirrors with equal priority or mirrors
# with lower priority when this network has NO free connections (see option
# NETWORK_MAX_CONNECTIONS in [network_connections] section of this file).
# Default:
# only_local_when_possible=1
-only_local_when_possible=1
+only_local_when_possible=1 \ No newline at end of file
diff --git a/segget/network1.conf b/segget/network1.conf
index 510e9d3..21ac1e1 100644
--- a/segget/network1.conf
+++ b/segget/network1.conf
@@ -183,7 +183,7 @@ use_own_mirror_list_only_on=1
# SYNOPSIS: ONLY_LOCAL_WHEN_POSSIBLE=0 | 1
# If NETWORK_USES_OWN_MIRROR_LIST_ONLY_ON=0 this option will be ignored.
# - If set to 1, segget will not use remote mirrors with equal or lower priority
-# untill all mirrors in network0_mirrors.conf file have failed.
+# until all mirrors in network0_mirrors.conf file have failed.
# - If set to 0, segget will use remote mirrors with equal priority or mirrors
# with lower priority when this network has NO free connections (see option
# NETWORK_MAX_CONNECTIONS in [network_connections] section of this file).
diff --git a/segget/provide_mirror_dir/.gitignore b/segget/provide_mirror_dir/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/segget/provide_mirror_dir/.gitignore
diff --git a/segget/segget.conf b/segget/segget.conf
index eab2763..901f8d9 100644
--- a/segget/segget.conf
+++ b/segget/segget.conf
@@ -160,8 +160,8 @@ benchmark_oblivion=5
# MIRROR_DIR
# Define a dir to store distfiles for mirroring.
# Default:
-# mirror_dir=./mirror
-# NOT IMPLEMENTED YET: mirror_dir=./mirror
+# provide_mirror_dir=./provide_mirror_dir
+provide_mirror_dir=./provide_mirror_dir
[networks]
# NETWORK0_PRIORITY
diff --git a/segget/settings.cpp b/segget/settings.cpp
index 66214e0..49cc568 100644
--- a/segget/settings.cpp
+++ b/segget/settings.cpp
@@ -52,6 +52,8 @@ 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");
+
ulong cur_network_priority;
for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
//set default values, in case segget.conf doesn't have these settings
diff --git a/segget/settings.h b/segget/settings.h
index c8aab5e..cb96de8 100644
--- a/segget/settings.h
+++ b/segget/settings.h
@@ -63,14 +63,8 @@ class Tsettings{
//mirrors
ulong max_connections_num_per_mirror;
ulong benchmark_oblivion;
- //user-data
- string user_agent;
- //proxy
- string proxy_ip_or_name;
- ulong proxy_port;
- bool proxy_off;
- string proxy_user;
- string proxy_password;
+ //provide_mirror_to_others
+ string provide_mirror_dir;
//logs
string logs_dir;
string general_log_file;
@@ -103,14 +97,8 @@ class Tsettings{
//mirrors
max_connections_num_per_mirror(1),
benchmark_oblivion(5),
- //user-data
- user_agent("segget"),
- //proxy
- proxy_ip_or_name("none"),
- proxy_port(3128),
- proxy_off(1),
- proxy_user("none"),
- proxy_password("none"),
+ //provide_mirror_to_others
+ provide_mirror_dir("./provide_mirror_dir"),
//logs
logs_dir("./logs"),
general_log_file("segget.log"),