Branch data Line data Source code
1 : : /*- 2 : : * Copyright (c) 2020 Baptiste Daroussin <bapt@FreeBSD.org> 3 : : * 4 : : * Redistribution and use in source and binary forms, with or without 5 : : * modification, are permitted provided that the following conditions 6 : : * are met: 7 : : * 1. Redistributions of source code must retain the above copyright 8 : : * notice, this list of conditions and the following disclaimer 9 : : * in this position and unchanged. 10 : : * 2. Redistributions in binary form must reproduce the above copyright 11 : : * notice, this list of conditions and the following disclaimer in the 12 : : * documentation and/or other materials provided with the distribution. 13 : : * 14 : : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 : : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 : : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 : : * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 : : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 : : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 : : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 : : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 : : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 : : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 : : */ 25 : : 26 : : #include <sys/stat.h> 27 : : #include <sys/param.h> 28 : : 29 : : #include <stdio.h> 30 : : #include <fetch.h> 31 : : #include <errno.h> 32 : : 33 : : #include "pkg.h" 34 : : #include "private/pkg.h" 35 : : #include "private/event.h" 36 : : #include "private/utils.h" 37 : : 38 : : int 39 : 983 : file_open(struct pkg_repo *repo, struct url *u, off_t *sz) 40 : : { 41 : : struct stat st; 42 : : 43 [ + + ]: 983 : if (stat(u->doc, &st) == -1) { 44 [ + + ]: 16 : if (!repo->silent) 45 : 12 : pkg_emit_error("%s://%s%s%s%s: %s", 46 : 12 : u->scheme, 47 : 12 : u->user, 48 : 12 : u->user[0] != '\0' ? "@" : "", 49 : 12 : u->host, 50 : 12 : u->doc, 51 : 12 : strerror(errno)); 52 : 16 : return (EPKG_FATAL); 53 : : } 54 : 967 : *sz = st.st_size; 55 : 967 : u->ims_time = st.st_mtime; 56 : : 57 : 967 : repo->fh = fopen(u->doc, "re"); 58 [ + - ]: 967 : if (repo->fh == NULL) 59 : 0 : return (EPKG_FATAL); 60 : 967 : return (EPKG_OK); 61 : 983 : }