Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.append does not differentiate between tabs and spaces #28586

Closed
zmalone opened this issue Nov 4, 2015 · 5 comments
Closed

file.append does not differentiate between tabs and spaces #28586

zmalone opened this issue Nov 4, 2015 · 5 comments
Labels
Bug broken, incorrect, or confusing behavior Execution-Module help-wanted Community help is needed to resolve this P4 Priority 4 Platform Relates to OS, containers, platform-based utilities like FS, system based apps severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@zmalone
Copy link
Contributor

zmalone commented Nov 4, 2015

given a sls file like:

test1:
  file.append:
    - name: /tmp/test.txt
    - text: "foo bar"
test2:
  file.append:
    - name: /tmp/test.txt
    - text: "foo    bar"

you would expect to see results of:

foo bar
foo bar

but instead you get

foo bar

as salt does not appear to differentiate between spaces and tabs for file.append. This is not documented on https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.append , and appears to be unintentional.

This was tested on 2015.8.1 on Ubuntu 14.04.

@jfindlay jfindlay added Execution-Module Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around P4 Priority 4 Platform Relates to OS, containers, platform-based utilities like FS, system based apps labels Nov 7, 2015
@jfindlay jfindlay added this to the Approved milestone Nov 7, 2015
@jfindlay jfindlay added the help-wanted Community help is needed to resolve this label Nov 7, 2015
@jfindlay
Copy link
Contributor

jfindlay commented Nov 7, 2015

@zmalone, thanks for the report.

@abednarik
Copy link
Contributor

I just saw this which looks like a check that removes any whitespace to compare file content with text content in state. This will probably will make that if you have something like "foo bar" and want to append "foo bar" call will return True and file will not be updated.
Regarding new content, I don't find where those white spaces are stripped.

@abednarik
Copy link
Contributor

Hi

Salt ignores white spaces.

  file.append:
    - name: /tmp/test1.txt
    - text: "foo                        bar"
          ID: common_hostsfile
    Function: file.append
        Name: /tmp/test1.txt
      Result: True
     Comment: Appended 1 lines
     Started: 18:08:00.188813
    Duration: 5.978 ms
     Changes:   
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -0,0 +1 @@
                  +foo                  bar
cat /tmp/test1.txt 
foo                     bar
Salt Version:
           Salt: 2015.8.3-138-g654cab0

Dependency Versions:
         Jinja2: 2.8
       M2Crypto: 0.21.1
           Mako: Not Installed
         PyYAML: 3.10
          PyZMQ: 15.1.0
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
           RAET: Not Installed
        Tornado: 4.3
            ZMQ: 4.1.2
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.13.0-68-generic
         system: Ubuntu 14.04 trusty

After updating state and remving all tabs whit a single space

  file.append:
    - name: /tmp/test1.txt
    - text: "foo bar"

No change is applied this will return True since all white space is ignored.

I see 2 alternatives: adding a note in the docs just to give advice regarding behavior or add one argument more in that function ignore_whitespace=True by default to not change any bahavior. In case you set ignore_whitespace to False that check will not run.

@jfindlay / @cachedout what do you think?

@jfindlay
Copy link
Contributor

jfindlay commented Jan 5, 2016

@abednarik, I think adding ignore_whitespace would be fine.

@abednarik
Copy link
Contributor

Hi @jfindlay

See #30156

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Execution-Module help-wanted Community help is needed to resolve this P4 Priority 4 Platform Relates to OS, containers, platform-based utilities like FS, system based apps severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

3 participants