gitlab-org--gitlab-foss/lib
Dmitriy Zaporozhets 0214a21db5 Merge branch 'restore_uploads_fix' into 'master'
Avoid "cannot copy directory ... to itself" error on restore (on Docker?)

rake gitlab:backup:restore fails for me in my Docker-hosted Gitlab-CE instance; during the restore, any existing "uploads" directory is backed up by [this code](https://gitlab.com/gitlab-org/gitlab-ce/blob/833bc30/lib/backup/uploads.rb#L23) --

```ruby
    def backup_existing_uploads_dir
      timestamped_uploads_path = File.join(app_uploads_dir, '..', "uploads.#{Time.now.to_i}")
      if File.exists?(app_uploads_dir)
        FileUtils.mv(app_uploads_dir, timestamped_uploads_path)
      end
    end
```

When this executes for me, the ```FileUtils.mv``` parameters are "/home/git/gitlab/public/uploads" and "/home/git/gitlab/public/uploads/../uploads.1407019546"; an exception is raised, producing this double stacktrace:

```
ArgumentError: cannot copy directory /home/git/gitlab/public/uploads to itself /home/git/gitlab/public/uploads/../uploads.1407019546
/home/git/gitlab/lib/backup/uploads.rb:26:in `backup_existing_uploads_dir'
/home/git/gitlab/lib/backup/uploads.rb:18:in `restore'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:73:in `block (4 levels) in <top (required)>'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:30:in `block (3 levels) in <top (required)>'
Errno::EXDEV: Invalid cross-device link @ sys_fail2 - (/home/git/gitlab/public/uploads, /home/git/gitlab/public/uploads/../uploads.1407019546)
/home/git/gitlab/lib/backup/uploads.rb:26:in `backup_existing_uploads_dir'
/home/git/gitlab/lib/backup/uploads.rb:18:in `restore'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:73:in `block (4 levels) in <top (required)>'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:30:in `block (3 levels) in <top (required)>'
Tasks: TOP => gitlab:backup:uploads:restore
(See full trace by running task with --trace)
```

I'm guessing from the first message that ```mv``` walks the destination path to ensure that we're not moving the source into itself -- it doesn't get as far as interpreting the '..', but throws when it sees that the destination appears to start with the source path.

The second stacktrace I have no clue about - maybe it's AUFS- or Docker-related?

I attempted to reproduce this separately with the omnibus distribution in a fresh Ubuntu 14.04 install without Docker involved, and was unable to - backup and restore worked fine. I then tested my theory by FileUtils.expand_path-ing the destination in my own Docker setup code, and that made the problem go away, so that's what this merge request does.

(I'm using backups created and restored on gitlab-ce 7-1-stable, at facfec4b2; this is on Ubuntu 14.04 with Docker 1.1.1)

I know I'd look askance at a PR without tests for an unreproducable problem, but even if this is rejected, I'm submitting it anyway because maybe someone else will Google it and find it useful. I'm happy to do more work to improve this if you have suggestions.

See merge request !165
2015-06-22 09:52:42 +00:00
..
api Fix editing files via API 2015-06-05 17:16:51 +02:00
assets
backup Merge branch 'restore_uploads_fix' into 'master' 2015-06-22 09:52:42 +00:00
gitlab Fix behavior of ldap_person method in Gitlab::OAuth::User 2015-06-17 18:06:27 +02:00
omni_auth Add reset_session for the :reset_session strategy. 2015-04-24 20:10:32 +02:00
redcarpet/render Fix typo. 2015-06-02 13:21:34 +02:00
support Update SSL ciphers per logjam vulnerability recommendations. 2015-06-15 11:40:00 +02:00
tasks An in_namespace scope is already present 2015-06-09 13:42:01 +02:00
disable_email_interceptor.rb Add email interceptor to prevent mail sending if email sending is disabled. 2014-10-27 13:05:50 +01:00
email_validator.rb More rubocop rules enable 2015-02-02 21:31:03 -08:00
event_filter.rb Add parenthesis to function def with arguments. 2014-10-03 09:18:46 +02:00
extracts_path.rb Upgrade to Rails 4.1.9 2015-02-14 11:09:23 -07:00
file_size_validator.rb Support configurable attachment size via Application Settings 2015-04-02 00:04:08 -07:00
gitlab.rb Add lib/gitlab.rb to autoload non-conventional paths 2015-04-09 14:19:25 -04:00
gt_one_coercion.rb
repository_cache.rb Fix RepositoryCache backend attr_reader 2015-01-30 10:17:55 -05:00
static_model.rb
unfold_form.rb
version_check.rb Replace host with real one 2015-05-11 18:21:45 +03:00