Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0117589a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0117589a
编写于
2月 14, 2019
作者:
R
Ryuta Kamizono
提交者:
GitHub
2月 14, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35266 from ricardotk002/use-dir-children
Use Dir#children and Dir#each_child in ActiveSupport::Cache::FileStore
上级
3f186e30
df29b664
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
4 addition
and
11 deletion
+4
-11
activesupport/lib/active_support/cache/file_store.rb
activesupport/lib/active_support/cache/file_store.rb
+3
-10
activesupport/test/cache/stores/file_store_test.rb
activesupport/test/cache/stores/file_store_test.rb
+1
-1
未找到文件。
activesupport/lib/active_support/cache/file_store.rb
浏览文件 @
0117589a
...
...
@@ -18,7 +18,6 @@ class FileStore < Store
DIR_FORMATTER
=
"%03X"
FILENAME_MAX_SIZE
=
228
# max filename size on file system is 255, minus room for timestamp and random characters appended by Tempfile (used by atomic write)
FILEPATH_MAX_SIZE
=
900
# max is 1024, plus some room
EXCLUDED_DIRS
=
[
"."
,
".."
].
freeze
GITKEEP_FILES
=
[
".gitkeep"
,
".keep"
].
freeze
def
initialize
(
cache_path
,
options
=
nil
)
...
...
@@ -35,7 +34,7 @@ def self.supports_cache_versioning?
# file store directory except for .keep or .gitkeep. Be careful which directory is specified in your
# config file when using +FileStore+ because everything in that directory will be deleted.
def
clear
(
options
=
nil
)
root_dirs
=
exclude_from
(
cache_path
,
EXCLUDED_DIRS
+
GITKEEP_FILES
)
root_dirs
=
(
Dir
.
children
(
cache_path
)
-
GITKEEP_FILES
)
FileUtils
.
rm_r
(
root_dirs
.
collect
{
|
f
|
File
.
join
(
cache_path
,
f
)
})
rescue
Errno
::
ENOENT
end
...
...
@@ -154,7 +153,7 @@ def file_path_key(path)
# Delete empty directories in the cache.
def
delete_empty_directories
(
dir
)
return
if
File
.
realpath
(
dir
)
==
File
.
realpath
(
cache_path
)
if
exclude_from
(
dir
,
EXCLUDED_DIRS
).
empty?
if
Dir
.
children
(
dir
).
empty?
Dir
.
delete
(
dir
)
rescue
nil
delete_empty_directories
(
File
.
dirname
(
dir
))
end
...
...
@@ -167,8 +166,7 @@ def ensure_cache_path(path)
def
search_dir
(
dir
,
&
callback
)
return
if
!
File
.
exist?
(
dir
)
Dir
.
foreach
(
dir
)
do
|
d
|
next
if
EXCLUDED_DIRS
.
include?
(
d
)
Dir
.
each_child
(
dir
)
do
|
d
|
name
=
File
.
join
(
dir
,
d
)
if
File
.
directory?
(
name
)
search_dir
(
name
,
&
callback
)
...
...
@@ -193,11 +191,6 @@ def modify_value(name, amount, options)
end
end
end
# Exclude entries from source directory
def
exclude_from
(
source
,
excludes
)
Dir
.
entries
(
source
).
reject
{
|
f
|
excludes
.
include?
(
f
)
}
end
end
end
end
activesupport/test/cache/stores/file_store_test.rb
浏览文件 @
0117589a
...
...
@@ -101,7 +101,7 @@ def test_delete_does_not_delete_empty_parent_dir
end
assert
File
.
exist?
(
cache_dir
),
"Parent of top level cache dir was deleted!"
assert
File
.
exist?
(
sub_cache_dir
),
"Top level cache dir was deleted!"
assert_empty
Dir
.
entries
(
sub_cache_dir
).
reject
{
|
f
|
ActiveSupport
::
Cache
::
FileStore
::
EXCLUDED_DIRS
.
include?
(
f
)
}
assert_empty
Dir
.
children
(
sub_cache_dir
)
end
def
test_log_exception_when_cache_read_fails
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录