diff options
author | jhb <jhb@FreeBSD.org> | 2000-07-25 23:22:16 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2000-07-25 23:22:16 +0000 |
commit | 4600fb1a7e25bffa13cd44b84ed7bfabdb751d15 (patch) | |
tree | 47a9677a9f574dd340094fd97275e9aee02fd4df /usr.sbin/sysinstall/ftp.c | |
parent | 7c0d02d7cb751b591a5842821fdf35f350b10f79 (diff) | |
download | FreeBSD-src-4600fb1a7e25bffa13cd44b84ed7bfabdb751d15.zip FreeBSD-src-4600fb1a7e25bffa13cd44b84ed7bfabdb751d15.tar.gz |
Use a much saner method of locating the release directory on an FTP server.
Now, if a release is specified, instead of just looking for a directory
with the same name as the release, try several possible directories (each
suffixed with the release name) relative to the base directory including
".", "releases/MACHINE", "snapshots/MACHINE", and each of those prefixed
with "pub/FreeBSD/". This will allow us to remove the evil symlinks under
pub/FreeBSD/releases/MACHINE/ to the snapshots on the ftp site.
Diffstat (limited to 'usr.sbin/sysinstall/ftp.c')
-rw-r--r-- | usr.sbin/sysinstall/ftp.c | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/usr.sbin/sysinstall/ftp.c b/usr.sbin/sysinstall/ftp.c index 9c0deb8..f83367e 100644 --- a/usr.sbin/sysinstall/ftp.c +++ b/usr.sbin/sysinstall/ftp.c @@ -48,6 +48,11 @@ Boolean ftpInitted = FALSE; static FILE *OpenConn; int FtpPort; +/* List of sub directories to look for under a given FTP server. */ +static const char *ftp_dirs[] = { ".", "releases/"MACHINE, "snapshots/"MACHINE, + "pub/FreeBSD", "pub/FreeBSD/releases/"MACHINE, + "pub/FreeBSD/snapshots/"MACHINE, NULL }; + /* Brings up attached network device, if any - takes FTP device as arg */ static Boolean netUp(Device *dev) @@ -73,7 +78,7 @@ netDown(Device *dev) Boolean mediaInitFTP(Device *dev) { - int i, code, af; + int i, code, af, fdir; char *cp, *rel, *hostname, *dir; char *user, *login_name, password[80]; @@ -141,32 +146,55 @@ try: } } - /* Give it a shot - can't hurt to try and zoom in if we can, unless the release is set to - __RELEASE or "none" which signifies that it's not set */ + /* + * Now that we've verified that the path we're given is ok, let's try to + * be a bit intelligent in locating the release we are looking for. First + * off, if the release is specified as "__RELEASE" or "none", then just + * assume that the current directory is the one we want and give up. + */ rel = variable_get(VAR_RELNAME); - if (strcmp(rel, "__RELEASE") && strcmp(rel, "none")) - i = ftpChdir(OpenConn, rel); - else - i = 0; - if (i) { - if (!msgYesNo("Warning: Can't CD to `%s' distribution on this\n" + if (strcmp(rel, "__RELEASE") && strcmp(rel, "none")) { + /* + * Ok, since we have a release variable, let's walk through the list + * of directories looking for a release directory. The first one to + * match wins. For each case, we chdir to ftp_dirs[fdir] first. If + * that fails, we skip to the next one. Otherwise, we try to chdir to + * rel. If it succeeds we break out. If it fails, then we go back to + * the base directory and try again. Lots of chdirs, but oh well. :) + */ + fdir = 0; + while (ftp_dirs[fdir] != NULL) { + if (ftpChdir(OpenConn, ftp_dirs[fdir++]) != 0) + continue; + if (ftpChdir(OpenConn, rel) == 0) { + ftpInitted = TRUE; + return TRUE; + } + ftpChdir(OpenConn, "/"); + if (dir && *dir != '\0') + ftpChdir(OpenConn, dir); + } + + /* + * If we get here, then all of the directories we tried failed, so + * print out the error message and ask the user if they want to try + * again. + */ + if (!msgYesNo("Warning: Can't find the `%s' distribution on this\n" "FTP server. You may need to visit a different server for\n" - "the release you're trying to fetch or go to the Options\n" + "the release you are trying to fetch or go to the Options\n" "menu and to set the release name to explicitly match what's\n" "available on %s (or set to \"none\").\n\n" "Would you like to select another FTP server?", rel, hostname)) { variable_unset(VAR_FTP_PATH); - if (DITEM_STATUS(mediaSetFTP(NULL)) == DITEM_FAILURE) - goto punt; - else + if (DITEM_STATUS(mediaSetFTP(NULL)) != DITEM_FAILURE) goto try; } - else - goto punt; + } else { + ftpInitted = TRUE; + return TRUE; } - ftpInitted = TRUE; - return TRUE; punt: ftpInitted = FALSE; |