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
...
@@ -118,41 +118,52 @@ class RepositoriesController < ApplicationController
# If the entry is a dir, show the browser
# If the entry is a dir, show the browser
(
show
;
return
)
if
@entry
.
is_dir?
(
show
;
return
)
if
@entry
.
is_dir?
@content
=
@repository
.
cat
(
@path
,
@rev
)
f
=
nil
(
show_error_not_found
;
return
)
unless
@content
begin
if
'raw'
==
params
[
:format
]
||
f
=
@repository
.
save_entry_to_temp_file
(
@path
,
@rev
)
(
@content
.
size
&&
@content
.
size
>
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
)
||
!
is_entry_text_data?
(
@content
,
@path
)
if
params
[
:format
]
==
'raw'
||
# Force the download
f
.
size
>
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
||
send_opt
=
{
:filename
=>
filename_for_content_disposition
(
@path
.
split
(
'/'
).
last
)
}
is_binary_data?
(
f
,
@path
)
send_type
=
Redmine
::
MimeType
.
of
(
@path
)
# Force the download
send_opt
[
:type
]
=
send_type
.
to_s
if
send_type
send_type
=
Redmine
::
MimeType
.
of
(
@path
)
send_data
@content
,
send_opt
options
=
{
else
:filename
=>
filename_for_content_disposition
(
@path
.
split
(
'/'
).
last
),
# Prevent empty lines when displaying a file with Windows style eol
:disposition
=>
'attachment'
# TODO: UTF-16
}
# Is this needs? AttachmentsController reads file simply.
options
[
:type
]
=
send_type
.
to_s
if
send_type
@content
.
gsub!
(
"
\r\n
"
,
"
\n
"
)
send_file
(
f
.
path
,
options
)
@changeset
=
@repository
.
find_changeset_by_name
(
@rev
)
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
end
end
def
is_entry_text_data?
(
ent
,
path
)
def
is_binary_data?
(
file
,
path
)
# UTF-16 contains "\x00".
# It is very strict that file contains less than 30% of ascii symbols
return
false
if
Redmine
::
MimeType
.
is_type?
(
'text'
,
path
)
# in non Western Europe.
return
true
if
Redmine
::
MimeType
.
is_type?
(
'text'
,
path
)
# First block of the file is examined for odd
# Ruby 1.8.6 has a bug of integer divisions.
# characters such as strange control codes or char-
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
# acters with the high bit set. If too many strange
if
ent
.
respond_to?
(
"is_binary_data?"
)
&&
ent
.
is_binary_data?
# Ruby 1.8.x and <1.9.2
# characters (>30%) are found, it's a binary file,
return
false
# otherwise it's a text file. Also, any file con-
elsif
ent
.
respond_to?
(
:force_encoding
)
&&
(
ent
.
dup
.
force_encoding
(
"UTF-8"
)
!=
ent
.
dup
.
force_encoding
(
"BINARY"
)
)
# Ruby 1.9.2
# taining null in the first block is considered a
# TODO: need to handle edge cases of non-binary content that isn't UTF-8
# binary file.
return
false
end
blk
=
file
.
read
(
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
)
true
return
blk
.
size
==
0
||
blk
.
count
(
"^ -~"
,
"^
\r\n
"
)
/
blk
.
size
>
0.3
||
blk
.
count
(
"
\x00
"
)
>
0
end
end
private
:is_
entry_text
_data?
private
:is_
binary
_data?
def
annotate
def
annotate
@entry
=
@repository
.
entry
(
@path
,
@rev
)
@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