VictoriaFreSh 2022.1.8 → 2022.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/victoriafresh.rb +58 -17
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a021bf4ba7e3c19fe3d303849da3fdbd5410f8188af87059e1ca404d77450bf8
|
|
4
|
+
data.tar.gz: 986f3fea84eb15ce0574edbfd6bb9247d00b9002e98080228d5b2c6a79283e53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d27b6fead18004368e8948f4e440b213874fe8edcf67b49a86f0ae7046c939125a035db420c865af3c5014f11fa3fb0df262ebc774199edbc043535f41fdfa0e
|
|
7
|
+
data.tar.gz: 7af520afdca24160b014aaeb3995f05418f09319df854d969f48b8e5c4319756336e1b4a886681d844a51d596dc1f2e49afdd419510a1af92eb3ae8aa10eba7a
|
data/lib/victoriafresh.rb
CHANGED
|
@@ -11,6 +11,7 @@ require 'digest'
|
|
|
11
11
|
class VictoriaFresh
|
|
12
12
|
attr_accessor :diskFlushSize #累积了这么多的数据就向磁盘写入,以减少内存占用
|
|
13
13
|
attr_accessor :diskFileName #向磁盘写入数据时的文件名或前缀
|
|
14
|
+
attr_accessor :ignoreFileName # 用于指定忽略文件名列表的配置文件的名字
|
|
14
15
|
attr_accessor :diskMultiFile #向磁盘写入时,是否要写多个文件
|
|
15
16
|
attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
|
|
16
17
|
attr_accessor :currentDiskFlushSuffix #当前的文件后缀。也等价于已经写入的文件片段个数
|
|
@@ -19,6 +20,7 @@ class VictoriaFresh
|
|
|
19
20
|
@diskFlush=false #要向磁盘写入文件
|
|
20
21
|
@diskFlushSize=143212 #磁盘分块大小
|
|
21
22
|
@diskFileName='victoriafreshdata.v' #磁盘文件名
|
|
23
|
+
@ignoreFileName=nil # 忽略文件名列表配置文件名
|
|
22
24
|
@diskMultiFile=false #磁盘整个文件,不是多个文件
|
|
23
25
|
@diskWriteFileObject={} #向磁盘写入文件的对象
|
|
24
26
|
@contentString="" #内容字符串
|
|
@@ -28,6 +30,7 @@ class VictoriaFresh
|
|
|
28
30
|
@externalDataFile={} #外部数据文件对象
|
|
29
31
|
@nextFileIdToUse=1 # 下一个要用的文件编号。
|
|
30
32
|
@md5FileIdMap={} # MD5 与文件编号之间的映射
|
|
33
|
+
@fileIdPathMap={} # 文件编号与它的实际路径之间的映射
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
# 计算文件内容的MD5。
|
|
@@ -72,15 +75,24 @@ class VictoriaFresh
|
|
|
72
75
|
def writeFileExternalDataFile(pathPrefix, packagedFile) #写入文件
|
|
73
76
|
timeObject=getTimeObject(packagedFile) #构造时间戳对象
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
is_duplicate=packagedFile['is_duplicate'] # 是否是重复文件。
|
|
79
|
+
fileId=packagedFile['id'] # 获取文件编号。
|
|
80
|
+
|
|
81
|
+
if is_duplicate # 是重复文件。
|
|
82
|
+
sameFileId=packagedFile['same_file_id'] # 找到相同文件的编号。
|
|
83
|
+
|
|
84
|
+
sameFilePath=@fileIdPathMap[sameFileId] # 获取原始相同文件的路径。
|
|
85
|
+
|
|
86
|
+
victoriaFreshData=File.read(sameFilePath) # 读取原始相同文件的内容。
|
|
87
|
+
else # 不是重复文件。
|
|
88
|
+
@externalDataFile.seek(packagedFile['file_start_index']) #定位到起始位置
|
|
89
|
+
|
|
90
|
+
victoriaFreshData=@externalDataFile.read(packagedFile['file_length']) #读取内容
|
|
91
|
+
end # if is_duplicate # 是重复文件。
|
|
81
92
|
|
|
82
|
-
# pathToMake=pathPrefix + '/' + packagedFile.name #构造文件名
|
|
83
93
|
pathToMake=pathPrefix + '/' + packagedFile['name'] #构造文件名
|
|
94
|
+
|
|
95
|
+
@fileIdPathMap[fileId]=pathToMake # 记录文件编号与路径之间的映射。
|
|
84
96
|
|
|
85
97
|
begin
|
|
86
98
|
victoriaFreshDataFile=File.new(pathToMake , "wb", packagedFile['permission']) #数据文件。
|
|
@@ -95,8 +107,6 @@ class VictoriaFresh
|
|
|
95
107
|
elsif #带权限字段
|
|
96
108
|
File.chmod(permissionNumber, pathToMake) #设置权限
|
|
97
109
|
end #if (permissionNumber.nil?) #不带权限字段
|
|
98
|
-
|
|
99
|
-
|
|
100
110
|
rescue Errno::ENOENT # File not exist
|
|
101
111
|
puts "Rescued by Errno::ENOENT statement. #{pathToMake}" #报告错误
|
|
102
112
|
rescue Errno::EACCES # File permission error
|
|
@@ -345,6 +355,31 @@ class VictoriaFresh
|
|
|
345
355
|
end #if (@diskFlush) #要做磁盘写入
|
|
346
356
|
end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
|
|
347
357
|
|
|
358
|
+
# 读取要忽略的文件名列表。
|
|
359
|
+
def readIgnoreFileList (directoryPathName)
|
|
360
|
+
current_paragraph=[] # 列表
|
|
361
|
+
#陈欣
|
|
362
|
+
datastore= "#{directoryPathName.expand_path}/#{@ignoreFileName}" # 配置文件路径
|
|
363
|
+
puts "reading ignore file: #{datastore}" # Debug
|
|
364
|
+
|
|
365
|
+
begin
|
|
366
|
+
File.foreach(datastore).with_index do |line, _line_num|
|
|
367
|
+
puts line.to_s # Debug
|
|
368
|
+
puts "#{line.empty?} #{line.length} #{line.strip.empty?}" # Debug
|
|
369
|
+
|
|
370
|
+
if line.strip.empty? # 空行
|
|
371
|
+
else # 不是空行
|
|
372
|
+
current_paragraph << line.strip # 记录一行
|
|
373
|
+
end # if line.strip.empty? # 空行
|
|
374
|
+
end # File&.foreach(datastore).with_index do |line, _line_num|
|
|
375
|
+
|
|
376
|
+
rescue Errno::ENOENT
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
puts "ignore list: #{current_paragraph}" # Debug
|
|
380
|
+
current_paragraph
|
|
381
|
+
end
|
|
382
|
+
|
|
348
383
|
def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
|
|
349
384
|
if (@diskFlush) #要向磁盘写入文件
|
|
350
385
|
if (layer==0) #最外层
|
|
@@ -357,8 +392,6 @@ class VictoriaFresh
|
|
|
357
392
|
|
|
358
393
|
packagedFile={} #创建文件消息对象。
|
|
359
394
|
|
|
360
|
-
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
|
361
|
-
|
|
362
395
|
directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
|
|
363
396
|
|
|
364
397
|
baseName=directoryPathName.basename.to_s #基本文件名。
|
|
@@ -373,8 +406,6 @@ class VictoriaFresh
|
|
|
373
406
|
|
|
374
407
|
packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
|
|
375
408
|
|
|
376
|
-
puts directoryPath #Dbug.
|
|
377
|
-
|
|
378
409
|
#记录时间戳:
|
|
379
410
|
begin #读取时间戳
|
|
380
411
|
mtimeStamp=File.mtime(directoryPath) #获取时间戳
|
|
@@ -389,7 +420,7 @@ class VictoriaFresh
|
|
|
389
420
|
end #begin #读取时间戳
|
|
390
421
|
|
|
391
422
|
if isFile #是文件,不用再列出其子文件了。
|
|
392
|
-
packagedFile['file_length']=
|
|
423
|
+
packagedFile['file_length']=0 #记录文件的内容长度。
|
|
393
424
|
packagedFile['id']= nextFileId # 设置下一个文件编号
|
|
394
425
|
|
|
395
426
|
#读取文件内容:
|
|
@@ -401,6 +432,8 @@ class VictoriaFresh
|
|
|
401
432
|
sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
|
|
402
433
|
|
|
403
434
|
if sameFileId.nil? # 不存在相同的文件
|
|
435
|
+
packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
|
|
436
|
+
|
|
404
437
|
@contentPartArray << currentFileContent
|
|
405
438
|
@bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
|
|
406
439
|
@md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
|
|
@@ -426,11 +459,17 @@ class VictoriaFresh
|
|
|
426
459
|
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
|
427
460
|
|
|
428
461
|
packagedFile['file_length']=0 #本目录的内容长度。
|
|
429
|
-
|
|
430
|
-
|
|
462
|
+
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
|
463
|
+
|
|
464
|
+
ignoreFileList=readIgnoreFileList(directoryPathName) # 读取要忽略的文件名列表。
|
|
431
465
|
|
|
432
466
|
directoryPathName.each_child do |subFile| #一个个文件地处理。
|
|
433
467
|
begin
|
|
468
|
+
subFilebaseName=subFile.basename.to_s #基本文件名。
|
|
469
|
+
|
|
470
|
+
if (ignoreFileList.include?(subFilebaseName)) # 是要忽略的文件
|
|
471
|
+
puts "ignore #{subFile}" # 报告,忽略。
|
|
472
|
+
else # 不忽略
|
|
434
473
|
realPath=subFile.expand_path #获取绝对路径。
|
|
435
474
|
|
|
436
475
|
packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
|
|
@@ -439,12 +478,14 @@ class VictoriaFresh
|
|
|
439
478
|
|
|
440
479
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
|
441
480
|
|
|
442
|
-
|
|
443
481
|
subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
|
|
444
482
|
|
|
445
483
|
# puts("237, content string length: #{contentString.length}") #Debug
|
|
446
484
|
|
|
447
485
|
packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
|
|
486
|
+
|
|
487
|
+
end
|
|
488
|
+
|
|
448
489
|
rescue Errno::EMFILE # File not exist
|
|
449
490
|
puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
|
|
450
491
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: VictoriaFreSh
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2022.1.
|
|
4
|
+
version: 2022.1.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hxcan Cai
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-01-
|
|
11
|
+
date: 2022-01-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: hx_cbor
|