Skip to content

--cycle keeps setting the same profile if update_mtime fails #412

Description

@m0ar

I'm configuring autorandr with Nix, both with home-manager on arch linux and on NixOS. In both scenarios, the config files for autorandr are linked from a readonly filesystem with a 0 timestamp:

❯ tree /etc/xdg         
/etc/xdg
└── autorandr
    ├── default
    │   ├── config -> /etc/static/xdg/autorandr/default/config
    │   ├── postswitch.d
    │   │   └── kb -> /etc/static/xdg/autorandr/default/postswitch.d/kb
    │   └── setup -> /etc/static/xdg/autorandr/default/setup
    └── office
        ├── config -> /etc/static/xdg/autorandr/office/config
        ├── postswitch.d
        │   └── kb -> /etc/static/xdg/autorandr/office/postswitch.d/kb
        └── setup -> /etc/static/xdg/autorandr/office/setup

❯ ls -lAL /etc/xdg/autorandr/*          
/etc/xdg/autorandr/default:
total 12
-r--r--r-- 1 root root   55 Jan  1  1970 config
drwxr-xr-x 2 root root 4096 Mar 24 12:20 postswitch.d
-r--r--r-- 1 root root 1295 Jan  1  1970 setup

/etc/xdg/autorandr/office:
total 12
-r--r--r-- 1 root root   55 Jan  1  1970 config
drwxr-xr-x 2 root root 4096 Mar 24 12:20 postswitch.d
-r--r--r-- 1 root root 1295 Jan  1  1970 setup

Why it fails

`--cycle will always select the first profile, since:

  • --cycle depends on sorting by mtime
  • os.utime will fail if the file is readonly
  • the return value indicating success from update_mtime is ignored, so the current (epoch 0) mtime stays

Here is the relevant code:

# toplevel, return value of update_mtime is ignored
            if "--dry-run" not in options:
                update_mtime(os.path.join(scripts_path, "config"))


def update_mtime(filename):
    "Update a file's mtime"
    try:
        os.utime(filename, None)
        return True
    except:
        # this will fail
        return False

Proposed fixes

Either:

  1. call os.utime with follow_symlinks = false, and update and read mtime from the link instead of the destination
  2. extend symlink profile detection to work with actual dirs for the autorandr and profiles dirs, but when the actual config is a symlink (not entirely sure how this part of the code works atm)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions