Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
79983afb
Commit
79983afb
authored
Jul 20, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use find instead Ruby to remove files due to performance reasons
parent
1bda4517
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
32 deletions
+12
-32
app/services/repository_archive_clean_up_service.rb
app/services/repository_archive_clean_up_service.rb
+4
-13
spec/services/repository_archive_clean_up_service_spec.rb
spec/services/repository_archive_clean_up_service_spec.rb
+8
-19
No files found.
app/services/repository_archive_clean_up_service.rb
View file @
79983afb
class
RepositoryArchiveCleanUpService
ALLOWED_ARCHIVE_EXTENSIONS
=
%w[tar tar.bz2 tar.gz zip]
.
join
(
','
).
freeze
LAST_MODIFIED_TIME_IN_MINUTES
=
120
def
initialize
(
mmin
=
LAST_MODIFIED_TIME_IN_MINUTES
)
...
...
@@ -21,22 +20,14 @@ class RepositoryArchiveCleanUpService
attr_reader
:mmin
,
:path
def
clean_up_old_archives
Dir
.
glob
(
"
#{
path
}
/**.git/*{
#{
ALLOWED_ARCHIVE_EXTENSIONS
}
}"
)
do
|
filename
|
File
.
delete
(
filename
)
if
older?
(
filename
)
end
end
def
older?
(
filename
)
File
.
exist?
(
filename
)
&&
File
.
new
(
filename
).
mtime
<
(
Time
.
now
-
mmin
*
60
)
run
(
%W(find
#{
path
}
-not -path
#{
path
}
-type f
\(
-name
\*
.tar -o -name
\*
.bz2 -o -name
\*
.tar.gz -o -name
\*
.zip
\)
-maxdepth 2 -mmin +
#{
mmin
}
-delete)
)
end
def
clean_up_empty_directories
Dir
.
glob
(
"
#{
path
}
/**.git/"
).
reverse_each
do
|
dir
|
Dir
.
rmdir
(
dir
)
if
empty?
(
dir
)
end
run
(
%W(find
#{
path
}
-not -path
#{
path
}
-type d -empty -name
\*
.git -maxdepth 1 -delete)
)
end
def
empty?
(
dir
)
(
Dir
.
entries
(
dir
)
-
%w[. ..]
).
empty?
def
run
(
cmd
)
Gitlab
::
Popen
.
popen
(
cmd
)
end
end
spec/services/repository_archive_clean_up_service_spec.rb
View file @
79983afb
...
...
@@ -30,13 +30,9 @@ describe RepositoryArchiveCleanUpService, services: true do
end
context
'when archives older than 2 hours exists'
do
before
do
allow_any_instance_of
(
File
).
to
receive
(
:mtime
).
and_return
(
2
.
hours
.
ago
)
end
it
'removes old files that matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
2
.
hours
)
service
.
execute
...
...
@@ -46,7 +42,7 @@ describe RepositoryArchiveCleanUpService, services: true do
it
'keeps old files that does not matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
2
.
hours
)
service
.
execute
...
...
@@ -56,7 +52,7 @@ describe RepositoryArchiveCleanUpService, services: true do
it
'keeps old files inside invalid directories'
do
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
2
.
hours
)
service
.
execute
...
...
@@ -66,13 +62,9 @@ describe RepositoryArchiveCleanUpService, services: true do
end
context
'when archives older than 2 hours does not exist'
do
before
do
allow_any_instance_of
(
File
).
to
receive
(
:mtime
).
and_return
(
1
.
hour
.
ago
)
end
it
'keeps files that matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
)
files
=
create_temporary_files
(
dirname
,
%w[tar tar.bz2 tar.gz zip]
,
1
.
hour
)
service
.
execute
...
...
@@ -82,7 +74,7 @@ describe RepositoryArchiveCleanUpService, services: true do
it
'keeps files that does not matches valid archive extensions'
do
dirname
=
File
.
join
(
path
,
'sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb]
,
1
.
hour
)
service
.
execute
...
...
@@ -92,7 +84,7 @@ describe RepositoryArchiveCleanUpService, services: true do
it
'keeps files inside invalid directories'
do
dirname
=
File
.
join
(
path
,
'john_doe/sample.git'
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
)
files
=
create_temporary_files
(
dirname
,
%w[conf rb tar tar.gz]
,
1
.
hour
)
service
.
execute
...
...
@@ -101,12 +93,9 @@ describe RepositoryArchiveCleanUpService, services: true do
end
end
def
create_temporary_files
(
dirname
,
extensions
)
def
create_temporary_files
(
dirname
,
extensions
,
mtime
)
FileUtils
.
mkdir_p
(
dirname
)
extensions
.
flat_map
do
|
extension
|
FileUtils
.
touch
(
File
.
join
(
dirname
,
"sample.
#{
extension
}
"
))
end
FileUtils
.
touch
(
extensions
.
map
{
|
ext
|
File
.
join
(
dirname
,
"sample.
#{
ext
}
"
)
},
mtime:
Time
.
now
-
mtime
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment