Xdg-users-dirs-update how to make folders permanent?

Hi everybody! this is my first post, i’m not sure if this is the right section, if it’s not please forgive me.

I usually always solve my problems reading documentations but this time i want to achieve something outside my skill-set.

xdg-users-dirs-update is supposed to respect the user decision if he wants to delete a folder, by not making it again.

I want to revert this behavior, i want the home folders to be made again on reload if i delete one of them.
Is there a way to achieve this?

Thanks everyone!

xdg-user-dirs-update is normally run automatically at login, but I suppose it would be possible to add a script to your Autostart with the following content… :arrow_down:

!#/bin/sh
xdg-user-dirs-update --force

If I understand the manual correctly, then the above should do what you’re asking for. :thinking:

edit the file user-dirs.dirs

➜  ~ cat .config/user-dirs.dirs                                                                                    17:26
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"
1 Like

–force is not very clear, i tried that manually and it didn’t do anything different.
Also --help doesnt provide any explaination

no need to add a script, the xdg-user-dirs-update.service is very easy to edit and modify.

i was surprised by --force not doing the job.

Where can i find a detailed documentation of the command?

Already done this.
Result of deleting a directory is a change in the user-dirs.dirs file

if i delete Music,

the line will become XDG_MUSIC_DIR="$HOME/" when the boot service run the update command.

man xdg-user-dirs-update

That’s where I got it. :man_shrugging:

1 Like

The functionality comes with the package xdg-user-dirs - if you remove the package - you remove the functionality.

I forgot about man, only tried - - help
That’s a good tip I haven’t been using Linux for a while.

I’ll try again to make sure I didn’t do some mistakes when I tried - - force.

I’ll let you know!

1 Like

My end goal is to always have those folders when I log in, even if I deleted them in a previous session.

How removing the package would help me?

Then I don’t understand what your issue is?

What about a simple shell script that runs on login? Add the following to your ~/.bashrc, or ~/.zshrc depending on what you use as your login shell… :arrow_down:

for folder in Desktop Documents Downloads Music Pictures Public Templates Videos
do
   [ ! -d "${HOME}"/"${folder}" ] && mkdir "${HOME}"/"${folder}"
done
unset folder

It’s not really an issue.
I want the folder to be there, no matter what.

The problem is that if I delete them, the service doesn’t make them again.

So I want the xdg-user-dirs-update.service to make the folder in case they are missing

It surely works, but I would like something cleaner.
I would like to use some xdg-user-dirs parameter to solve this.

Are you sure that would be cleaner, since it is apparently not designed to do what you want it to do, and that, as a system-wide service, the file may possibly end up overwritten upon an update?

I’m not sure config files would be overwritten on updating, I think the update is only about the software package.

I tried with - - force and it didn’t restore my deleted folder. This is weird because the man page says that this parameter is meant to do exactly this.

May be a bug?

If - - force was working my plan was to modify the service file, and make it call the function with the - - force parameter.
I think this would survive a package update.

Can some of you check if the command:
xdg-user-dirs-update - - force
Restore a deleted folder?

Can you help me figuring out why it doesn’t work?

I consulted man and it seems it should work :man_shrugging:

Thank you very much for your time

You should add a disclaimer, this might have (unwanted) side effects for some configurations and could potentially change user-dirs.dir. To quote the man page:

xdg-user-dirs-update updates the current state of the users user-dirs.dir

If an old configuration exists it is updated with any new default directories.

Yes it says that, but I don’t understand the meaning very well.

It seems it means that if the configuration file already exists it doesn’t create folders, it creates folders only if user-dirs.dir doesn’t exist?

Because I’m experimenting exactly this.
Instead of create folders it just update the configuration file to be coherent to the existing directory.

I don’t understand 2 things:

1.What’s the difference between using --force and not using it?
2. Why do we need the service running every boot?

It does basically nothing. I don’t understand the purpose of the package at all!
The only thing it does it’s updating a configuration file only useful for itself?

I’m confused!

Keep in mind that English is not my native language so it’s possible I didn’t understand some subtlety in the man page.

A .service file is not a config file, and it would be overwritten if upstream felt that there was a need for a change to the file’s content.

Config files on the other hand are normally never overwritten. The new config file will be stored with a .pacnew filename suffix.

1 Like

ohhh thank you!! i didnt’t know that!
i just learned something new :slight_smile:

apparently my solution wasn’t clean at all! thank you for pointing that out.

1 Like

Which is why my shell script higher up is the right way to do what you want. :stuck_out_tongue:

1 Like