git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/4] clone: factor out dir_exists() helper

From
Jeff King <peff@peff.net>
Date
Jan 5, 2018, 00:22 UTC
Message-ID
<20180105002206.GB3474@sigill.intra.peff.net>
In-Reply-To
<20180104235412.GA3474@sigill.intra.peff.net>
On Thu, Jan 04, 2018 at 06:54:12PM -0500, Jeff King wrote:
Show 14 quoted lines
> > If we really want to be anal, perhaps a new helper path_exists()
> > that cares only about existence of paths (i.e. the implementation of
> > these two helpers they currently have), together with update to
> > check the st.st_mode for file_exists() and dir_exists(), may help
> > making the API set more rational, but I do not think it is worth it.
> 
> Yep, I also considered that file_exists() probably wants to be
> path_exists() with its current implementation. We'd probably want to
> review all of the callers.
> 
> Anyway, I tried to do the minimal refactoring here, with no change in
> behavior. I'm not opposed to calling this dir_exists() as path_exists()
> and making it globally available (as you note, I don't think we'd want
> to use a true dir_exists() here).

So I actually started down this road just now, but I'm not sure if it's worth it. If we were to transition to an endgame with path_exists(), dir_exists(), and file_exists(), we'd probably want to do something like:

  1. introduce path_exists(), but leave existing file_exists() callers
     in place
  2. introduce file_exists_as_file(), which checks S_IFREG
  3. audit each file_exists() call to see if it ought to be
     path_exists() or file_exists_as_file() and convert as needed
  4. When there are no more file_exists() calls left, all
     file_exists_as_file() instances can be renamed to file_exists().

But as with any "audit each..." plan, that leaves topics in flight out of luck. If we want to be kind to those, we'd have to wait a long while to shake out any file_exists() callers.

At which point is there much value in having path_exists() as a wrapper? It's a better name, perhaps, but I think my future-proofing against "file_exists() may become file-specific" was probably overly paranoid. I don't think we could sanely do that conversion without risking breakage.

Maybe we should just document its behavior and use it here, rather than introducing this new dir_exists().

-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 10 of 16 in “Git removes existing folder when cancelling clone”
  1. Stephan JanssenJan 2, 2018
  2. Robert P. J. DayJan 2, 2018
  3. Jeff KingJan 2, 2018
  4. 0/4 Git removes existing folder when cancelling cloneJeff King, Jan 2, 2018
  5. 1/4 t5600: fix outdated comment about unborn HEADJeff King, Jan 2, 2018
  6. 2/4 t5600: modernize styleJeff King, Jan 2, 2018
  7. 3/4 clone: factor out dir_exists() helperJeff King, Jan 2, 2018
  8. Junio C HamanoJan 4, 2018
  9. Jeff KingJan 4, 2018
  10. Jeff KingJan 5, 2018
  11. Junio C HamanoJan 5, 2018
  12. 4/4 clone: do not clean up directories we didn't createJeff King, Jan 2, 2018
  13. Eric SunshineJan 2, 2018
  14. Jeff KingJan 2, 2018
  15. Junio C HamanoJan 5, 2018
  16. Junio C HamanoJan 4, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.