Project

General

Profile

Bug #1102 ยป downloadOnlyServers.patch

Working patch - ximes, 2016-09-14 04:54 PM

View differences:

lib/libalpm/alpm.h
998 998
alpm_list_t *alpm_db_get_servers(const alpm_db_t *db);
999 999
int alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers);
1000 1000
int alpm_db_add_server(alpm_db_t *db, const char *url);
1001
int alpm_db_add_download_server(alpm_db_t *db, const char *url);
1001 1002
int alpm_db_remove_server(alpm_db_t *db, const char *url);
1002 1003
/** @} */
1003 1004

  
lib/libalpm/db.c
193 193
	return 0;
194 194
}
195 195

  
196
/** Add a download server to a database.
197
 * @param db database pointer
198
 * @param url url of the server
199
 * @return 0 on success, -1 on error (pm_errno is set accordingly)
200
 */
201
int SYMEXPORT alpm_db_add_download_server(alpm_db_t *db, const char *url)
202
{
203
	char *newurl;
204

  
205
	/* Sanity checks */
206
	ASSERT(db != NULL, return -1);
207
	db->handle->pm_errno = 0;
208
	ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
209

  
210
	newurl = sanitize_url(url);
211
	if(!newurl) {
212
		return -1;
213
	}
214
	db->download_servers = alpm_list_add(db->download_servers, newurl);
215
	_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding new download server URL to database '%s': %s\n",
216
			db->treename, newurl);
217

  
218
	return 0;
219
}
220

  
196 221
/** Remove a download server from a database.
197 222
 * @param db database pointer
198 223
 * @param url url of the server
lib/libalpm/db.h
70 70
	alpm_pkghash_t *pkgcache;
71 71
	alpm_list_t *grpcache;
72 72
	alpm_list_t *servers;
73
	alpm_list_t *download_servers;
73 74
	struct db_operations *ops;
74 75
	/* flags determining validity, local, loaded caches, etc. */
75 76
	enum _alpm_dbstatus_t status;
lib/libalpm/sync.c
884 884
		if(spkg->origin != ALPM_PKG_FROM_FILE && repo == spkg->origin_data.db) {
885 885
			alpm_list_t *delta_path = spkg->delta_path;
886 886

  
887
			if(!repo->servers) {
887
			if(!repo->download_servers) {
888 888
				handle->pm_errno = ALPM_ERR_SERVER_NONE;
889 889
				_alpm_log(handle, ALPM_LOG_ERROR, "%s: %s\n",
890 890
						alpm_strerror(handle->pm_errno), repo->treename);
......
898 898
					alpm_delta_t *delta = dlts->data;
899 899
					if(delta->download_size != 0) {
900 900
						struct dload_payload *payload = build_payload(
901
								handle, delta->delta, delta->delta_size, repo->servers);
901
								handle, delta->delta, delta->delta_size, repo->download_servers);
902 902
						ASSERT(payload, return -1);
903 903
						*files = alpm_list_add(*files, payload);
904 904
					}
......
909 909
			} else if(spkg->download_size != 0) {
910 910
				struct dload_payload *payload;
911 911
				ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
912
				payload = build_payload(handle, spkg->filename, spkg->size, repo->servers);
912
				payload = build_payload(handle, spkg->filename, spkg->size, repo->download_servers);
913 913
				ASSERT(payload, return -1);
914 914
				*files = alpm_list_add(*files, payload);
915 915
			}
src/pacman/conf.c
165 165
	}
166 166
	free(repo->name);
167 167
	FREELIST(repo->servers);
168
	FREELIST(repo->download_servers);
168 169
	free(repo);
169 170
}
170 171

  
......
648 649
	return 0;
649 650
}
650 651

  
652
static int _add_download_mirror(alpm_db_t *db, char *value)
653
{
654
	const char *dbname = alpm_db_get_name(db);
655
	/* let's attempt a replacement for the current repo */
656
	char *temp = strreplace(value, "$repo", dbname);
657
	/* let's attempt a replacement for the arch */
658
	const char *arch = config->arch;
659
	char *server;
660
	if(arch) {
661
		server = strreplace(temp, "$arch", arch);
662
		free(temp);
663
	} else {
664
		if(strstr(temp, "$arch")) {
665
			free(temp);
666
			pm_printf(ALPM_LOG_ERROR,
667
					_("download mirror '%s' contains the '%s' variable, but no '%s' is defined.\n"),
668
					value, "$arch", "Architecture");
669
			return 1;
670
		}
671
		server = temp;
672
	}
673

  
674
	if(alpm_db_add_download_server(db, server) != 0) {
675
		/* pm_errno is set by alpm_db_setserver */
676
		pm_printf(ALPM_LOG_ERROR, _("could not add download server URL to database '%s': %s (%s)\n"),
677
				dbname, server, alpm_strerror(alpm_errno(config->handle)));
678
		free(server);
679
		return 1;
680
	}
681

  
682
	free(server);
683
	return 0;
684
}
685

  
651 686
static int register_repo(config_repo_t *repo)
652 687
{
653 688
	alpm_list_t *i;
......
679 714
		}
680 715
	}
681 716

  
717
	for(i = repo->download_servers; i; i = alpm_list_next(i)) {
718
		char *value = i->data;
719
		if(_add_download_mirror(db, value) != 0) {
720
			pm_printf(ALPM_LOG_ERROR,
721
					_("could not add download mirror '%s' to database '%s' (%s)\n"),
722
					value, repo->name, alpm_strerror(alpm_errno(config->handle)));
723
			return 1;
724
		}
725
	}	
726
	
682 727
	return 0;
683 728
}
684 729

  
......
892 937
			ret = 1;
893 938
		} else {
894 939
			repo->servers = alpm_list_add(repo->servers, strdup(value));
940
			repo->download_servers = alpm_list_add(repo->download_servers, strdup(value));
941
		}
942
	} else if(strcmp(key, "ServerNoUpdate") == 0) {
943
		if(!value) {
944
			pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
945
					file, line, key);
946
			ret = 1;
947
		} else {
948
			repo->download_servers = alpm_list_add(repo->download_servers, strdup(value));
895 949
		}
896 950
	} else if(strcmp(key, "SigLevel") == 0) {
897 951
		if(!value) {
src/pacman/conf.h
37 37
typedef struct __config_repo_t {
38 38
	char *name;
39 39
	alpm_list_t *servers;
40
	alpm_list_t *download_servers;
40 41
	alpm_db_usage_t usage;
41 42
	alpm_siglevel_t siglevel;
42 43
	alpm_siglevel_t siglevel_mask;
    (1-1/1)