Commit Diff
- Commit:
f4f42cd328771f335ec1dc15884f2bf337bdf36a
- From:
- Omar Polo <op@omarpolo.com>
- Date:
- Message:
- fix cd Walk can be successful in various conditions where cd has to fail. For instance, we may have reached a file or we couldn't walk all the required components. In these "soft-fail" cases, the walk has mutated the fids, so to abort the cd we have to do a walk using a second fid and then clunk the old or new one depending on if it was _completely_ successful or not. Another option may be to track the number of walked path and attempt to walk '..' the right amount of times, this would saves a Tclunk in the case the walk succeeded and require a slightly bigger 9P packet to be sent in the failure case. It would complicate the walk_path API though, so I've not chosen this option.
- Actions:
- Patch | Tree
--- ftp.c +++ ftp.c @@ -708,15 +708,22 @@ static void cmd_cd(int argc, const char **argv) { struct qid qid; + int nfid; if (argc != 1) { printf("usage: cd remote-path\n"); return; } - if (walk_path(pwdfid, pwdfid, argv[0], &qid) == -1 || - !(qid.type & QTDIR)) + nfid = pwdfid+1; + if (walk_path(pwdfid, nfid, argv[0], &qid) == -1 || + !(qid.type & QTDIR)) { printf("can't cd %s\n", argv[0]); + do_clunk(nfid); + } else { + do_clunk(pwdfid); + pwdfid = nfid; + } } static void