Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
2aee0f09
Commit
2aee0f09
authored
Apr 18, 2012
by
Enrique García Cota
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated repo controller, too
parent
dd596d6d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
31 deletions
+42
-31
repositories_controller.rb
app/controllers/repositories_controller.rb
+42
-31
No files found.
app/controllers/repositories_controller.rb
View file @
2aee0f09
...
...
@@ -118,41 +118,52 @@ class RepositoriesController < ApplicationController
# If the entry is a dir, show the browser
(
show
;
return
)
if
@entry
.
is_dir?
@content
=
@repository
.
cat
(
@path
,
@rev
)
(
show_error_not_found
;
return
)
unless
@content
if
'raw'
==
params
[
:format
]
||
(
@content
.
size
&&
@content
.
size
>
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
)
||
!
is_entry_text_data?
(
@content
,
@path
)
# Force the download
send_opt
=
{
:filename
=>
filename_for_content_disposition
(
@path
.
split
(
'/'
).
last
)
}
send_type
=
Redmine
::
MimeType
.
of
(
@path
)
send_opt
[
:type
]
=
send_type
.
to_s
if
send_type
send_data
@content
,
send_opt
else
# Prevent empty lines when displaying a file with Windows style eol
# TODO: UTF-16
# Is this needs? AttachmentsController reads file simply.
@content
.
gsub!
(
"
\r\n
"
,
"
\n
"
)
@changeset
=
@repository
.
find_changeset_by_name
(
@rev
)
f
=
nil
begin
f
=
@repository
.
save_entry_to_temp_file
(
@path
,
@rev
)
if
params
[
:format
]
==
'raw'
||
f
.
size
>
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
||
is_binary_data?
(
f
,
@path
)
# Force the download
send_type
=
Redmine
::
MimeType
.
of
(
@path
)
options
=
{
:filename
=>
filename_for_content_disposition
(
@path
.
split
(
'/'
).
last
),
:disposition
=>
'attachment'
}
options
[
:type
]
=
send_type
.
to_s
if
send_type
send_file
(
f
.
path
,
options
)
else
@content
=
f
.
read
@changeset
=
@repository
.
find_changeset_by_name
(
@rev
)
end
rescue
Errno
::
ENOENT
show_error_not_found
return
ensure
f
.
close
if
f
end
end
def
is_entry_text_data?
(
ent
,
path
)
# UTF-16 contains "\x00".
# It is very strict that file contains less than 30% of ascii symbols
# in non Western Europe.
return
true
if
Redmine
::
MimeType
.
is_type?
(
'text'
,
path
)
# Ruby 1.8.6 has a bug of integer divisions.
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
if
ent
.
respond_to?
(
"is_binary_data?"
)
&&
ent
.
is_binary_data?
# Ruby 1.8.x and <1.9.2
return
false
elsif
ent
.
respond_to?
(
:force_encoding
)
&&
(
ent
.
dup
.
force_encoding
(
"UTF-8"
)
!=
ent
.
dup
.
force_encoding
(
"BINARY"
)
)
# Ruby 1.9.2
# TODO: need to handle edge cases of non-binary content that isn't UTF-8
return
false
end
true
def
is_binary_data?
(
file
,
path
)
return
false
if
Redmine
::
MimeType
.
is_type?
(
'text'
,
path
)
# First block of the file is examined for odd
# characters such as strange control codes or char-
# acters with the high bit set. If too many strange
# characters (>30%) are found, it's a binary file,
# otherwise it's a text file. Also, any file con-
# taining null in the first block is considered a
# binary file.
blk
=
file
.
read
(
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
)
return
blk
.
size
==
0
||
blk
.
count
(
"^ -~"
,
"^
\r\n
"
)
/
blk
.
size
>
0.3
||
blk
.
count
(
"
\x00
"
)
>
0
end
private
:is_
entry_text
_data?
private
:is_
binary
_data?
def
annotate
@entry
=
@repository
.
entry
(
@path
,
@rev
)
...
...
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