#NEWLINE# def verify_files( files , user ) : #NEWLINE# #INDENT# '\n    Verify that the named files exist and are owned by the named user\n    ' #NEWLINE# if salt . utils . is_windows ( ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# import pwd #NEWLINE# try : #NEWLINE# #INDENT# pwnam = pwd . getpwnam ( user ) #NEWLINE# uid = pwnam [ 2 ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# err = 'Failed to prepare the Salt environment for user {0}. The user is not available.\n' . format ( user ) #NEWLINE# sys . stderr . write ( err ) #NEWLINE# sys . exit ( salt . defaults . exitcodes . EX_NOUSER ) #NEWLINE# #UNINDENT# for fn_ in files : #NEWLINE# #INDENT# dirname = os . path . dirname ( fn_ ) #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . makedirs ( dirname ) #NEWLINE# #UNINDENT# except OSError as err : #NEWLINE# #INDENT# if ( err . errno != errno . EEXIST ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# if ( not os . path . isfile ( fn_ ) ) : #NEWLINE# #INDENT# with salt . utils . fopen ( fn_ , 'w+' ) as fp_ : #NEWLINE# #INDENT# fp_ . write ( '' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except IOError as err : #NEWLINE# #INDENT# if os . path . isfile ( dirname ) : #NEWLINE# #INDENT# msg = 'Failed to create path {0}, is {1} a file?' . format ( fn_ , dirname ) #NEWLINE# raise SaltSystemExit ( msg = msg ) #NEWLINE# #UNINDENT# if ( err . errno != errno . EACCES ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# msg = 'No permissions to access "{0}", are you running as the correct user?' . format ( fn_ ) #NEWLINE# raise SaltSystemExit ( msg = msg ) #NEWLINE# #UNINDENT# except OSError as err : #NEWLINE# #INDENT# msg = 'Failed to create path "{0}" - {1}' . format ( fn_ , err ) #NEWLINE# raise SaltSystemExit ( msg = msg ) #NEWLINE# #UNINDENT# stats = os . stat ( fn_ ) #NEWLINE# if ( uid != stats . st_uid ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . chown ( fn_ , uid , ( - 1 ) ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return True