File tree 3 files changed +20
-8
lines changed 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -416,9 +416,17 @@ def with_index(new_index) # :yields: new_index
416
416
end
417
417
418
418
def with_temp_index &blk
419
- tempfile = Tempfile . new ( 'temp-index' )
420
- temp_path = tempfile . path
421
- tempfile . unlink
419
+ # Workaround for JRUBY, since they handle the TempFile path different.
420
+ # MUST be improved to be safer and OS independent.
421
+ if RUBY_PLATFORM == 'java'
422
+ temp_path = "/tmp/temp-index-#{ ( 0 ...15 ) . map { ( 'a' ..'z' ) . to_a [ rand ( 26 ) ] } . join } "
423
+ else
424
+ tempfile = Tempfile . new ( 'temp-index' )
425
+ temp_path = tempfile . path
426
+ tempfile . close
427
+ tempfile . unlink
428
+ end
429
+
422
430
with_index ( temp_path , &blk )
423
431
end
424
432
@@ -466,6 +474,7 @@ def with_working(work_dir) # :yields: the Git::WorkingDirectory
466
474
def with_temp_working &blk
467
475
tempfile = Tempfile . new ( "temp-workdir" )
468
476
temp_dir = tempfile . path
477
+ tempfile . close
469
478
tempfile . unlink
470
479
Dir . mkdir ( temp_dir , 0700 )
471
480
with_working ( temp_dir , &blk )
Original file line number Diff line number Diff line change 1
1
module Git
2
- class Path
2
+
3
+ class Path
3
4
4
5
attr_accessor :path
5
6
6
- def initialize ( path , check_path = true )
7
- if !check_path || File . exists? ( path )
8
- @path = File . expand_path ( path )
9
- else
7
+ def initialize ( path , check_path = true )
8
+ if check_path && !File . exists? ( path )
10
9
raise ArgumentError , 'path does not exist' , [ File . expand_path ( path ) ]
11
10
end
11
+
12
+ @path = File . expand_path ( path )
12
13
end
13
14
14
15
def readable?
@@ -24,4 +25,5 @@ def to_s
24
25
end
25
26
26
27
end
28
+
27
29
end
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ def test_read_tree
90
90
91
91
tmp = Tempfile . new ( 'tesxt' )
92
92
tmppath = tmp . path
93
+ tmp . close
93
94
tmp . unlink
94
95
95
96
g . with_index ( tmppath ) do
You can’t perform that action at this time.
0 commit comments