--- login.c.orig Thu Apr 19 16:45:32 2001 +++ login.c Sun Mar 3 14:20:35 2002 @@ -320,36 +320,42 @@ passfile = construct_cvspass_filename (); fp = CVS_FOPEN (passfile, "r"); - if (fp == NULL) + + /* If the file doesn't exist, we simply treat it as an empty file */ + if (fp == NULL && operation != password_entry_add) { error (0, errno, "failed to open %s for reading", passfile); goto error_exit; } - cvsroot_canonical = normalize_cvsroot (root); - - /* Check each line to see if we have this entry already. */ - line = 0; - while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0) - { - line++; - password = password_entry_parseline(cvsroot_canonical, 1, line, linebuf); - if (password != NULL) - /* this is it! break out and deal with linebuf */ - break; - } - if (line_length < 0 && !feof (fp)) + if (fp != NULL) { - error (0, errno, "cannot read %s", passfile); - goto error_exit; + cvsroot_canonical = normalize_cvsroot (root); + + /* Check each line to see if we have this entry already. */ + line = 0; + while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0) + { + line++; + password = password_entry_parseline(cvsroot_canonical, 1, line, linebuf); + if (password != NULL) + /* this is it! break out and deal with linebuf */ + break; + } + if (line_length < 0 && !feof (fp)) + { + error (0, errno, "cannot read %s", passfile); + goto error_exit; + } + if (fclose (fp) < 0) + /* not fatal, unless it cascades */ + error (0, errno, "cannot close %s", passfile); + fp = NULL; } - if (fclose (fp) < 0) - /* not fatal, unless it cascades */ - error (0, errno, "cannot close %s", passfile); - fp = NULL; /* Utter, total, raving paranoia, I know. */ - chmod (passfile, 0600); + if (isfile (passfile)) + chmod (passfile, 0600); /* a copy to return or keep around so we can reuse linebuf */ if (password != NULL)