Skip to content

Save does not return an error when the file does not exist #13

Open

Description

@roidelapluie

in roidelapluie/go-augtest@dca84f5

the file /tmp/foo/bar does not exist, is not created, but still augeas.Save() does not return an error.

Activity

  1. hillu commented on May 11, 2017

    @hillu

    Just tried to reproduce the error. Apparently, the directory must exist. Tried the following in an empty directory (augeas 1.8, Debian/stretch chroot):

    $ augtool --root .
    augtool> set /augeas/load/Xmgmt/lens Sshd.lns
    augtool> set /augeas/load/Xmgmt/incl /tmp/foo/bar
    augtool> set /files/tmp/foo/bar/X11Forwarding no
    augtool> save
    error: Failed to execute command
    saving failed (run 'errors' for details)
    augtool> errors
    Error in /tmp/foo/bar (mk_augtemp)
      No such file or directory
    

    I can confirm that your test program produces no error -- this is a bug in the library, indeed.

    After creating the directory and repeating the procedure everything works fine from augtool.

  2. hillu commented on May 11, 2017

    @hillu

    Digging further... a simple C test program to reproduce this issue behaves correctly in the sense that -1 is returned.

    #include <stdio.h>
    #include <augeas.h>
    #include <assert.h>
    
    int main(int argc, char** argv) {
      augeas *a;
      int r;
      a = aug_init("./", "", 0);
      assert(a != NULL);
      r = aug_load(a);
      r = aug_set(a, "/augeas/load/Xmgmt/lens", "Sshd.lns");
      assert(r!=-1);
      r = aug_set(a, "/augeas/load/Xmgmt/incl", "/tmp/foo/bar");
      assert(r!=-1);
      r = aug_set(a, "/files/tmp/foo/bar/X11Forwarding", "no");
      assert(r!=-1);
      r = aug_save(a);
      printf("aug_save: %d\n", r);
      printf("code: %d, msg: %s, minormsg: %s, details: %s\n",
    	 aug_error(a),
    	 aug_error_message(a),
    	 aug_error_minor_message(a),
    	 aug_error_details(a));
      assert(r==0);
    }

    However, the aug_error_* functions return nothing sensible:

    aug_save: -1
    code: 0, msg: No error, minormsg: (null), details: (null)
    13t: 13t.c:24: main: Assertion `r==0' failed.
    Aborted
    

    augtool tells us to get the errors through a dedicated command which prints out the messages from the /augeas//error tree... go-augeas should probably return a generic error in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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