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

salt.states.file.copy force=true on Windows does not clear the Read-Only attribute during removal #51739

Closed
arizvisa opened this issue Feb 20, 2019 · 3 comments
Labels
Bug broken, incorrect, or confusing behavior P4 Priority 4 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@arizvisa
Copy link
Contributor

Description of Issue/Question

On the windows platform, when using file.copy where the source has a file with a read-only attribute (attrib +r), the call to file.remove fails with an exception and so the whole state fails.

Setup

Setup a Windows box, drop a directory with some files that have the readonly attribute set. You can enable the +r attribute via attrib +r $filename at the command prompt.

Steps to Reproduce Issue

Once you have a source directory with the prior mentioned constraints, just use a state with file.copy and the force parameter set to true. After the copy happens, the second time you apply the state you'll get the following exception:

          ID: Copy harness stage into target path
    Function: file.copy
        Name: R:\harness
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "c:\salt\bin\lib\site-packages\salt\state.py", line 1913, in call
                  **cdata['kwargs'])
                File "c:\salt\bin\lib\site-packages\salt\loader.py", line 1898, in wrapper
                  return f(*args, **kwargs)
                File "c:\salt\bin\lib\site-packages\salt\states\file.py", line 5757, in copy
                  __salt__['file.remove'](name)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1093, in remove
                  remove(item, force)
                File "c:\salt\bin\lib\site-packages\salt\modules\win_file.py", line 1102, in remove
                  'Could not remove \'{0}\': {1}'.format(path, exc)
              CommandExecutionError: Could not remove 'R:\harness\BugId\.git\modules\modules\cBugId\modules\modules\mFileSystem\modules\modules\mWindowsAPI\objects\pack\pack-f43ecb13511b485fc9417c2aeb795ac9bc24a914.idx': [Error 5] Access is denied: u'R:\\harness\\BugId\\.git\\modules\\modules\\cBugId\\modules\\modules\\mFileSystem\\modules\\modules\\mWindowsAPI\\objects\\pack\\pack-f43ecb13511b485fc9417c2aeb795ac9bc24a914.idx'

Versions Report

Salt Version:
           Salt: 2018.3.3

Dependency Versions:
           cffi: 1.10.0
       cherrypy: 10.2.1
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: 2.0.5
      gitpython: 2.1.3
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: 1.6.1
       M2Crypto: Not Installed
           Mako: 1.0.7
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.17
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]
   python-gnupg: 0.4.1
         PyYAML: 3.12
          PyZMQ: 16.0.3
           RAET: Not Installed
          smmap: 2.0.5
        timelib: 0.2.4
        Tornado: 4.5.1
            ZMQ: 4.1.6

System Versions:
           dist:
         locale: cp1252
        machine: AMD64
        release: 8
         system: Windows
        version: 8 6.2.9200 SP0 Multiprocessor Free
@arizvisa
Copy link
Contributor Author

The issue is that the call to file.remove in the file.copy state is also not setting the force parameter to true. It looks like:

            # Remove the destination to prevent problems later
            try:
                __salt__['file.remove'](name)
            except (IOError, OSError):
                return _error(
                    ret,
                    'Failed to delete "{0}" in preparation for '
                    'forced move'.format(name)
                )

I'll submit a PR for this one too.

@Ch3LL
Copy link
Contributor

Ch3LL commented Feb 21, 2019

thanks for the pr!

@Ch3LL Ch3LL added Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around P4 Priority 4 team-windows labels Feb 21, 2019
@Ch3LL Ch3LL modified the milestones: Blocked, Approved Feb 21, 2019
dwoz added a commit to arizvisa/saltstack-salt that referenced this issue Mar 5, 2019
dwoz added a commit that referenced this issue Mar 7, 2019
Updated the salt.states.file.copy function to make the call to file.remove with the force parameter set to the same as one for salt.states.file.copy.
@arizvisa
Copy link
Contributor Author

arizvisa commented Mar 7, 2019

Closing this issue as it appears the PR was merged.

@arizvisa arizvisa closed this as completed Mar 7, 2019
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 P4 Priority 4 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

2 participants