forked from vieter-v/vieter
				
			Changed behavior for default_arch variable
							parent
							
								
									6479071fd7
								
							
						
					
					
						commit
						9d8491a77a
					
				|  | @ -72,10 +72,13 @@ pub fn (r &RepoGroupManager) add_pkg_from_path(repo string, pkg_path string) ?Re | |||
| 
 | ||||
| // add_pkg_in_repo adds a package to a given repo. This function is responsible | ||||
| // for inspecting the package architecture. If said architecture is 'any', the | ||||
| // package is added to each arch-repository within the given repo. If none | ||||
| // exist, one is created for provided r.default_arch value. If the architecture | ||||
| // isn't 'any', the package is only added to the specific architecture. | ||||
| // package is added to each arch-repository within the given repo. A package of | ||||
| // architecture 'any' will always be added to the arch-repo defined by | ||||
| // r.default_arch. If this arch-repo doesn't exist yet, it will be created. If | ||||
| // the architecture isn't 'any', the package is only added to the specific | ||||
| // architecture. | ||||
| fn (r &RepoGroupManager) add_pkg_in_repo(repo string, pkg &package.Pkg) ?bool { | ||||
| 	// A package without arch 'any' can be handled without any further checks | ||||
| 	if pkg.info.arch != 'any' { | ||||
| 		return r.add_pkg_in_arch_repo(repo, pkg.info.arch, pkg) | ||||
| 	} | ||||
|  | @ -84,15 +87,17 @@ fn (r &RepoGroupManager) add_pkg_in_repo(repo string, pkg &package.Pkg) ?bool { | |||
| 
 | ||||
| 	mut arch_repos := []string{} | ||||
| 
 | ||||
| 	// If this is the first package to be added to the repository, it won't | ||||
| 	// contain any arch-repos yet. | ||||
| 	// If this is the first package that's added to the repo, the directory | ||||
| 	// won't exist yet | ||||
| 	if os.exists(repo_dir) { | ||||
| 		// We get a listing of all currently present arch-repos in the given repo | ||||
| 		arch_repos = os.ls(repo_dir) ?.filter(os.is_dir(os.join_path_single(repo_dir, | ||||
| 			it))) | ||||
| 	} | ||||
| 
 | ||||
| 	if arch_repos.len == 0 { | ||||
| 	// The default_arch should always be updated when a package with arch 'any' | ||||
| 	// is added. | ||||
| 	if !arch_repos.contains(r.default_arch) { | ||||
| 		arch_repos << r.default_arch | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ pub: | |||
| 	api_key      string | ||||
| 	data_dir     string | ||||
| 	repos_file   string | ||||
| 	default_arch string | ||||
| } | ||||
| 
 | ||||
| // cmd returns the cli submodule that handles starting the server | ||||
|  |  | |||
|  | @ -58,10 +58,6 @@ fn (mut app App) put_package(repo string) web.Result { | |||
| 		// Generate a random filename for the temp file | ||||
| 		pkg_path = os.join_path_single(app.conf.download_dir, rand.uuid_v4()) | ||||
| 
 | ||||
| 		for os.exists(pkg_path) { | ||||
| 			pkg_path = os.join_path_single(app.conf.download_dir, rand.uuid_v4()) | ||||
| 		} | ||||
| 
 | ||||
| 		app.ldebug("Uploading $length bytes (${util.pretty_bytes(length.int())}) to '$pkg_path'.") | ||||
| 
 | ||||
| 		// This is used to time how long it takes to upload a file | ||||
|  |  | |||
|  | @ -20,6 +20,11 @@ pub mut: | |||
| 
 | ||||
| // server starts the web server & starts listening for requests | ||||
| pub fn server(conf Config) ? { | ||||
| 	// Prevent using 'any' as the default arch | ||||
| 	if conf.default_arch == 'any' { | ||||
| 		util.exit_with_message(1, "'any' is not allowed as the value for default_arch.") | ||||
| 	} | ||||
| 
 | ||||
| 	// Configure logger | ||||
| 	log_level := log.level_from_tag(conf.log_level) or { | ||||
| 		util.exit_with_message(1, 'Invalid log level. The allowed values are FATAL, ERROR, WARN, INFO & DEBUG.') | ||||
|  | @ -39,7 +44,7 @@ pub fn server(conf Config) ? { | |||
| 	} | ||||
| 
 | ||||
| 	// This also creates the directories if needed | ||||
| 	repo := repo.new(conf.data_dir, conf.pkg_dir, 'x86_64') or { | ||||
| 	repo := repo.new(conf.data_dir, conf.pkg_dir, conf.default_arch) or { | ||||
| 		logger.error(err.msg) | ||||
| 		exit(1) | ||||
| 	} | ||||
|  |  | |||
							
								
								
									
										4
									
								
								test.py
								
								
								
								
							
							
						
						
									
										4
									
								
								test.py
								
								
								
								
							|  | @ -46,7 +46,7 @@ def create_random_pkginfo(words, name_min_len, name_max_len): | |||
|         "pkgname": name, | ||||
|         "pkgbase": name, | ||||
|         "pkgver": ver, | ||||
|         "arch": "x86_64" | ||||
|         "arch": "any" | ||||
|     } | ||||
| 
 | ||||
|     return "\n".join(f"{key} = {value}" for key, value in data.items()) | ||||
|  | @ -97,7 +97,7 @@ async def upload_random_package(tar_path, sem): | |||
|     async with sem: | ||||
|         with open(tar_path, 'rb') as f: | ||||
|             async with aiohttp.ClientSession() as s: | ||||
|                 async with s.post("http://localhost:8000/vieter2/publish", data=f.read(), headers={"x-api-key": "test"}) as r: | ||||
|                 async with s.post("http://localhost:8000/vieter/publish", data=f.read(), headers={"x-api-key": "test"}) as r: | ||||
|                     return await check_output(r) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,5 +5,6 @@ data_dir = "data" | |||
| pkg_dir = "data/pkgs" | ||||
| log_level = "DEBUG" | ||||
| repos_file = "data/repos.json" | ||||
| default_arch = "x86_64" | ||||
| 
 | ||||
| address = "http://localhost:8000" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue