Git Product home page Git Product logo

Comments (3)

adrg avatar adrg commented on May 25, 2024

I don't really understand your point here. Each path in the paths slice is checked in turn for existence. And the paths are sorted by their priority (home directory paths first).

If we take the xdg.DataFile function as an example. Let's say these are the searched paths:
[~/.local/share, /usr/local/share, /usr/share] (composed by XDG_DATA_HOME + XDG_DATA_DIRS)
and I want to create myapp/app.data.

In that case, createPath would first look if ~/.local/share/myapp exists. If it doesn't, it would create it and stop.
If the directories cannot be created, the next path in the paths slice is attempted and so on until it succeeds or there are no more paths.

The files should always be written in the order of the paths, even though not all of them exist. If the first one in the slice does not exist, it should be created. If that succeeds, then that's the path at which the data file should be written.

EDIT: in your example, /usr/local/share would not be created because a home directory path of the root user would be attempted first. Only if that fails, the next path is attempted. And as I mentioned, priority matters. Paths should be created in the order of the priority they are defined either in the XDG variable in question or in the order of the defaults if that variable is not set.

from xdg.

adrg avatar adrg commented on May 25, 2024

@KalleDK Can this issue be closed?

To summarize:

createPath is used by xdg.DataFile, xdg.ConfigFile, xdg.CacheFile, xdg.RuntimeFile and xdg.StateFile.
For all of them, paths are created relative to XDG_DATA_HOME, XDG_CONFIG_HOME, XDG_CACHE_HOME, XDG_RUNTIME_DIR and XDG_STATE_HOME. Defaults are used for variables which are not defined or are empty.

For xdg.DataFile and xdg.ConfigFile, in addition to XDG_DATA_HOME and XDG_CONFIG_HOME, XDG_DATA_DIRS and XDG_CONFIG_DIRS are used as fallbacks. They are used only if paths cannot be created relative to XDG_DATA_HOME and XDG_CONFIG_HOME. So that should never happen, as users should always be able to create directories inside their home directory. However, if that happens for any reason, path creation is attempted relative to the paths defined by XDG_DATA_DIRS/XDG_CONFIG_DIRS, in the order they are defined in the variable by the user/system (or in the order of the defaults if it is not defined). Realistically, fallbacks are never used.

from xdg.

adrg avatar adrg commented on May 25, 2024

Closing this issue. Please re-open if I missed anything.

from xdg.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.