Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u3d/sanitize: support dot_not_move #293

Merged
merged 2 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ Right now u3d has light support for build numbers. The build number can be found

![u3d sanitize](https://github.com/DragonBox/u3d/raw/master/docs/assets/u3d_sanitize.png)

If you wish a particular Unity installation to be ignored by the sanitization feature, create a `.u3d_do_not_move` file inside it.

## Security

When you install Unity with this tool, you will have to grant it higher privileges so it can perform the installation. It means that under MacOS and Linux, you will be asked for your `sudo` password.
Expand Down
26 changes: 23 additions & 3 deletions lib/u3d/installation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
## --- END LICENSE BLOCK ---

require 'u3d/utils'
require 'fileutils'

module U3d
UNITY_DIR_CHECK = /Unity_\d+\.\d+\.\d+[a-z]\d+/
UNITY_DIR_CHECK_LINUX = /unity-editor-\d+\.\d+\.\d+[a-z]\d+\z/
U3D_DO_NOT_MOVE = ".u3d_do_not_move".freeze

class Installation
attr_reader :root_path
Expand Down Expand Up @@ -67,6 +69,18 @@ def packages
false
end

def do_not_move?
File.exist?(@root_path) && File.exist?(do_not_move_file_path)
end

def do_not_move!(dry_run: false)
if dry_run
UI.message "Would create '#{do_not_move_file_path}'"
else
FileUtils.touch do_not_move_file_path
end
end

def package_installed?(package)
return true if (packages || []).include?(package)

Expand All @@ -78,6 +92,12 @@ def package_installed?(package)

return !(aliases & packages).empty?
end

private

def do_not_move_file_path
File.join(@root_path, U3D_DO_NOT_MOVE)
end
end

class PlaybackEngineUtils
Expand Down Expand Up @@ -152,7 +172,7 @@ def module_name_pattern(module_name)
end

def clean_install?
!(root_path =~ UNITY_DIR_CHECK).nil?
do_not_move? || !(root_path =~ UNITY_DIR_CHECK).nil?
end

private
Expand Down Expand Up @@ -257,7 +277,7 @@ def module_name_pattern(module_name)
end

def clean_install?
!(root_path =~ UNITY_DIR_CHECK_LINUX).nil?
do_not_move? || !(root_path =~ UNITY_DIR_CHECK_LINUX).nil?
end
end

Expand Down Expand Up @@ -372,7 +392,7 @@ def module_name_pattern(module_name)
end

def clean_install?
!(root_path =~ UNITY_DIR_CHECK).nil?
do_not_move? || !(root_path =~ UNITY_DIR_CHECK).nil?
end
end
end
53 changes: 53 additions & 0 deletions spec/u3d/installation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@
expect(unity.path).to eq('/Applications/Unity_5.6.0f1/Unity.app')
end

it "detects non clean install based on path name" do
unity = U3d::Installation.create(root_path: '/Applications/Unity/Unity.app')
expect(unity.clean_install?).to eq(false)
end

it "creates a Mac installation" do
unity = U3d::Installation.create(root_path: '/Applications/Unity_5.6.0f1')

expect(unity.class).to eq(U3d::MacInstallation)
expect(unity.path).to eq('/Applications/Unity_5.6.0f1/Unity.app')
expect(unity.exe_path).to eq('/Applications/Unity_5.6.0f1/Unity.app/Contents/MacOS/Unity')
expect(unity.clean_install?).to eq(true)
expect(unity.do_not_move?).to eq(false)
expect(unity.root_path).to eq('/Applications/Unity_5.6.0f1')
end
end
Expand All @@ -58,11 +64,18 @@
expect(unity.path).to eq('/opt/unity-editor-5.6.0f1')
end

it "detects non clean install based on path name" do
unity = U3d::Installation.create(root_path: '/opt/unity-editor')
expect(unity.clean_install?).to eq(false)
end

it "creates a Linux installation" do
unity = U3d::Installation.create(root_path: '/opt/unity-editor-5.6.0f1')

expect(unity.class).to eq(U3d::LinuxInstallation)
expect(unity.path).to eq('/opt/unity-editor-5.6.0f1')
expect(unity.clean_install?).to eq(true)
expect(unity.do_not_move?).to eq(false)
expect(unity.root_path).to eq('/opt/unity-editor-5.6.0f1')
end
end
Expand All @@ -77,14 +90,54 @@
expect(unity.path).to eq('C:/Program Files/Unity_2017.1.0f3')
end

it "detects non clean install based on path name" do
unity = U3d::Installation.create(root_path: 'C:/Program Files/Unity')
expect(unity.clean_install?).to eq(false)
end

it "creates a Windows installation" do
unity = U3d::Installation.create(root_path: 'C:/Program Files/Unity_2017.1.0f3')

expect(unity.class).to eq(U3d::WindowsInstallation)
expect(unity.path).to eq('C:/Program Files/Unity_2017.1.0f3')
expect(unity.clean_install?).to eq(true)
expect(unity.do_not_move?).to eq(false)
expect(unity.root_path).to eq('C:/Program Files/Unity_2017.1.0f3')
end
end

context "Any installation" do
before(:each) do
on_mac
end

it "supports installations that can move" do
expect(File).to receive(:exist?).with('/Applications/Unity') { true }
expect(File).to receive(:exist?).with('/Applications/Unity/.u3d_do_not_move') { false }

unity = U3d::Installation.create(root_path: '/Applications/Unity')
expect(unity.send(:do_not_move_file_path)).to eq('/Applications/Unity/.u3d_do_not_move')
expect(unity.clean_install?).to eq(false)
end

it "supports installations that cannot move" do
expect(File).to receive(:exist?).with('/Applications/Unity') { true }
expect(File).to receive(:exist?).with('/Applications/Unity/.u3d_do_not_move') { true }

unity = U3d::Installation.create(root_path: '/Applications/Unity')
expect(unity.send(:do_not_move_file_path)).to eq('/Applications/Unity/.u3d_do_not_move')
expect(unity.clean_install?).to eq(true)
end

it "supports marking installations to not move" do
expect(File).to receive(:exist?).with('/Applications/Unity') { true }
expect(File).to receive(:exist?).with('/Applications/Unity/.u3d_do_not_move') { true }

unity = U3d::Installation.create(root_path: '/Applications/Unity')
expect(unity.send(:do_not_move_file_path)).to eq('/Applications/Unity/.u3d_do_not_move')
expect(unity.clean_install?).to eq(true)
end
end
end
end
end