fixSingleFileWriteFlags fixes write flags on a single file If lockablePatterns is non-nil, then any file matching those patterns will be checked to see if it is currently locked by the current committer, and if so it will be writeable, and if not locked it will be read-only. If unlockablePatterns is
(file string, lockable, unlockable *filepathfilter.Filter)
| 161 | // be made writeable if it is not already. This can be used to reset files to |
| 162 | // writeable when their 'lockable' attribute is turned off. |
| 163 | func (c *Client) fixSingleFileWriteFlags(file string, lockable, unlockable *filepathfilter.Filter) error { |
| 164 | // Convert to git-style forward slash separators if necessary |
| 165 | // Necessary to match attributes |
| 166 | if filepath.Separator == '\\' { |
| 167 | file = strings.Replace(file, "\\", "/", -1) |
| 168 | } |
| 169 | if lockable != nil && lockable.Allows(file) { |
| 170 | // Lockable files are writeable only if they're currently locked |
| 171 | err := tools.SetFileWriteFlag(file, c.IsFileLockedByCurrentCommitter(file)) |
| 172 | // Ignore not exist errors |
| 173 | if err != nil && !os.IsNotExist(err) { |
| 174 | return err |
| 175 | } |
| 176 | } else if unlockable != nil && unlockable.Allows(file) { |
| 177 | // Unlockable files are always writeable |
| 178 | // We only check files which match the incoming patterns to avoid |
| 179 | // checking every file in the system all the time, and only do it |
| 180 | // when a file has had its lockable attribute removed |
| 181 | err := tools.SetFileWriteFlag(file, true) |
| 182 | if err != nil && !os.IsNotExist(err) { |
| 183 | return err |
| 184 | } |
| 185 | } |
| 186 | return nil |
| 187 | } |
no test coverage detected