HalosGhost / pbpst

A command-line libcurl C client for pb deployments
GNU General Public License v2.0
44 stars 9 forks source link

Implement the Local Database #12

Closed HalosGhost closed 9 years ago

HalosGhost commented 9 years ago

Prerequisites:

We need to get the local database up and running so we can simplify the output we give on successful completion and so we can support a lot of the planned options.

Things which must work to close:

HalosGhost commented 9 years ago

Process for locating the database:

  1. Check to see if we were told to use a specific file.
    • If so, check to see if that file exists
      • if so, and we have access to it, we're done.
      • if not, initialize it.
  2. Check to see if $XDG_CONFIG_HOME exists.
    • If so, check if $XDG_CONFIG_HOME/pbpst/ exists.
      • if so, check if $XDG_CONFIG_HOME/pbpst/db.json exists.
      • if so, and we have access to it, we're done.
      • if not, initialize it.
      • If not, create all missing parts of the path and initialize $XDG_CONFIG_HOME/pbpst/db.json.
  3. If not, check if $HOME/.config/pbpst/db.json exists.
    • If so, and we have access to it, we're done.
    • If not, create all missing parts of the path and initialize it.

Yes, this is a ton of steps just to ensure that we have a database. But, to preserve sanity and functionality, we need all of them.

HalosGhost commented 9 years ago

I'm pushing the db initialization to a little later in the stage so it'll be handled by writing the default to the swap db rather than writing the default to the main db for read-in. I may change my mind about this when we get to the swap db code handling; but, for now, that's the plan.

Edit: I found a great middle-ground. If the db we try to read in is empty, we read in the default db to the internal memory instead, and then the rest of the program executes as normal. This means there is only one special case to deal with the db init, that supporting an option exclusively to initialize the db is a cakewalk, and that we still do not need to worry about reading and writing to the same file.

HalosGhost commented 9 years ago

via 84b3086