From 25935f830220213a71c07dd1a443b715bb04ede5 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 25 Sep 2014 21:28:21 +0000 Subject: [PATCH] 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. --- lib/producer/core/actions/mkdir.rb | 6 ++---- lib/producer/core/remote/fs.rb | 4 ++++ spec/producer/core/actions/mkdir_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) 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