Improve mkdir so that permissions will be forced:

SFTP will honor umask on server side, and new directories won't get
expected permissions. We need to explicitly set permissions metadata for
new entries.
This commit is contained in:
Thibault Jouan 2014-09-25 21:28:21 +00:00
parent bd66ec25e4
commit 25935f8302
3 changed files with 8 additions and 6 deletions

View File

@ -9,10 +9,8 @@ module Producer
def apply def apply
Pathname.new(path).descend do |p| Pathname.new(path).descend do |p|
next if fs.dir? p next if fs.dir? p
case arguments.size fs.mkdir p.to_s
when 1 then fs.mkdir p.to_s fs.chmod p.to_s, mode if mode
when 2 then fs.mkdir p.to_s, mode
end
end end
end end

View File

@ -20,6 +20,10 @@ module Producer
false false
end end
def chmod(path, mode)
sftp.setstat! path, permissions: mode
end
def mkdir(path, mode = nil) def mkdir(path, mode = nil)
options = mode ? { permissions: mode } : {} options = mode ? { permissions: mode } : {}
sftp.mkdir! path, options sftp.mkdir! path, options

View File

@ -19,8 +19,8 @@ module Producer::Core
context 'when a mode was given' do context 'when a mode was given' do
subject(:mkdir) { Mkdir.new(env, path, 0700) } subject(:mkdir) { Mkdir.new(env, path, 0700) }
it 'creates the directory with given mode' do it 'changes the directory with given mode' do
expect(remote_fs).to receive(:mkdir).with(anything, 0700) expect(remote_fs).to receive(:chmod).with(path, 0700)
mkdir.apply mkdir.apply
end end
end end