diff --git a/lib/producer/core/actions/mkdir.rb b/lib/producer/core/actions/mkdir.rb index 1648c3a..b62170c 100644 --- a/lib/producer/core/actions/mkdir.rb +++ b/lib/producer/core/actions/mkdir.rb @@ -9,10 +9,8 @@ module Producer def apply Pathname.new(path).descend do |p| next if fs.dir? p - case arguments.size - when 1 then fs.mkdir p.to_s - when 2 then fs.mkdir p.to_s, mode - end + fs.mkdir p.to_s + fs.chmod p.to_s, mode if mode end end diff --git a/lib/producer/core/remote/fs.rb b/lib/producer/core/remote/fs.rb index 38091a5..478aaa4 100644 --- a/lib/producer/core/remote/fs.rb +++ b/lib/producer/core/remote/fs.rb @@ -20,6 +20,10 @@ module Producer false end + def chmod(path, mode) + sftp.setstat! path, permissions: mode + end + def mkdir(path, mode = nil) options = mode ? { permissions: mode } : {} sftp.mkdir! path, options diff --git a/spec/producer/core/actions/mkdir_spec.rb b/spec/producer/core/actions/mkdir_spec.rb index 8f7d23a..44dfc94 100644 --- a/spec/producer/core/actions/mkdir_spec.rb +++ b/spec/producer/core/actions/mkdir_spec.rb @@ -19,8 +19,8 @@ module Producer::Core context 'when a mode was given' do subject(:mkdir) { Mkdir.new(env, path, 0700) } - it 'creates the directory with given mode' do - expect(remote_fs).to receive(:mkdir).with(anything, 0700) + it 'changes the directory with given mode' do + expect(remote_fs).to receive(:chmod).with(path, 0700) mkdir.apply end end