VictoriaFreSh 2022.1.9 → 2022.1.27
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 +44 -10
- 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: bfb840c0cb2badb82e8518e77c2911bf0604533ee751a0292fe64a928fe68a42
|
4
|
+
data.tar.gz: 9a5c8667b3a714b922d22b638745526044cc0de79a265ce3f7d50dc08bcc47e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 314494a3924b7122ace2a3dbf3ce5facf217493e255c8b4628fb15125556b33fb8adce788c28d688ddfc604e0ba6e5c479e89c8901f560cab55709156a33febb
|
7
|
+
data.tar.gz: d494de1a1131a9514fa1c3bf90875ec6cdd2746a217d68c90c0d83b498d0593ecbe4388138a54a2a80e59e1cc3d7c99ced463743df3aaf542edecaf5bf16d5a6
|
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="" #内容字符串
|
@@ -74,7 +76,7 @@ class VictoriaFresh
|
|
74
76
|
timeObject=getTimeObject(packagedFile) #构造时间戳对象
|
75
77
|
|
76
78
|
is_duplicate=packagedFile['is_duplicate'] # 是否是重复文件。
|
77
|
-
|
79
|
+
fileId=packagedFile['id'] # 获取文件编号。
|
78
80
|
|
79
81
|
if is_duplicate # 是重复文件。
|
80
82
|
sameFileId=packagedFile['same_file_id'] # 找到相同文件的编号。
|
@@ -353,6 +355,31 @@ class VictoriaFresh
|
|
353
355
|
end #if (@diskFlush) #要做磁盘写入
|
354
356
|
end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
|
355
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
|
+
|
356
383
|
def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
|
357
384
|
if (@diskFlush) #要向磁盘写入文件
|
358
385
|
if (layer==0) #最外层
|
@@ -365,8 +392,6 @@ class VictoriaFresh
|
|
365
392
|
|
366
393
|
packagedFile={} #创建文件消息对象。
|
367
394
|
|
368
|
-
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
369
|
-
|
370
395
|
directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
|
371
396
|
|
372
397
|
baseName=directoryPathName.basename.to_s #基本文件名。
|
@@ -381,8 +406,6 @@ class VictoriaFresh
|
|
381
406
|
|
382
407
|
packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
|
383
408
|
|
384
|
-
puts directoryPath #Dbug.
|
385
|
-
|
386
409
|
#记录时间戳:
|
387
410
|
begin #读取时间戳
|
388
411
|
mtimeStamp=File.mtime(directoryPath) #获取时间戳
|
@@ -397,18 +420,21 @@ class VictoriaFresh
|
|
397
420
|
end #begin #读取时间戳
|
398
421
|
|
399
422
|
if isFile #是文件,不用再列出其子文件了。
|
400
|
-
packagedFile['file_length']=
|
423
|
+
packagedFile['file_length']=0 #记录文件的内容长度。
|
401
424
|
packagedFile['id']= nextFileId # 设置下一个文件编号
|
402
425
|
|
403
426
|
#读取文件内容:
|
404
427
|
fileToReadContent=File.new(directoryPath,"rb") #创建文件。
|
405
428
|
currentFileContent=fileToReadContent.read #全部读取
|
429
|
+
fileToReadContent.close # 关闭文件
|
406
430
|
|
407
431
|
currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
|
408
432
|
|
409
433
|
sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
|
410
434
|
|
411
435
|
if sameFileId.nil? # 不存在相同的文件
|
436
|
+
packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
|
437
|
+
|
412
438
|
@contentPartArray << currentFileContent
|
413
439
|
@bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
|
414
440
|
@md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
|
@@ -434,11 +460,17 @@ class VictoriaFresh
|
|
434
460
|
subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
|
435
461
|
|
436
462
|
packagedFile['file_length']=0 #本目录的内容长度。
|
437
|
-
|
438
|
-
|
463
|
+
packagedFile['sub_files'] = [] #加入到子文件列表中。
|
464
|
+
|
465
|
+
ignoreFileList=readIgnoreFileList(directoryPathName) # 读取要忽略的文件名列表。
|
439
466
|
|
440
467
|
directoryPathName.each_child do |subFile| #一个个文件地处理。
|
441
468
|
begin
|
469
|
+
subFilebaseName=subFile.basename.to_s #基本文件名。
|
470
|
+
|
471
|
+
if (ignoreFileList.include?(subFilebaseName)) # 是要忽略的文件
|
472
|
+
puts "ignore #{subFile}" # 报告,忽略。
|
473
|
+
else # 不忽略
|
442
474
|
realPath=subFile.expand_path #获取绝对路径。
|
443
475
|
|
444
476
|
packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
|
@@ -447,13 +479,15 @@ class VictoriaFresh
|
|
447
479
|
|
448
480
|
assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
|
449
481
|
|
450
|
-
|
451
482
|
subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
|
452
483
|
|
453
484
|
# puts("237, content string length: #{contentString.length}") #Debug
|
454
485
|
|
455
486
|
packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
|
456
|
-
|
487
|
+
|
488
|
+
end
|
489
|
+
|
490
|
+
rescue Errno::EMFILE # too many open Files in process
|
457
491
|
puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
|
458
492
|
end
|
459
493
|
end #directoryPathName.each_child do |subFile| #一个个文件地处理。
|
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.27
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hx_cbor
|