VictoriaFreSh 2022.1.27 → 2022.2.19

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/victoriafresh.rb +143 -131
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfb840c0cb2badb82e8518e77c2911bf0604533ee751a0292fe64a928fe68a42
4
- data.tar.gz: 9a5c8667b3a714b922d22b638745526044cc0de79a265ce3f7d50dc08bcc47e0
3
+ metadata.gz: 8196fd50e73107e811b5e7df7ba1d81f2f42b71b346ff444f29c98e26402008b
4
+ data.tar.gz: a3a4f2dee44ff0402497c8693dd8573392ff4d1187bfd622ef78cbbf270c0553
5
5
  SHA512:
6
- metadata.gz: 314494a3924b7122ace2a3dbf3ce5facf217493e255c8b4628fb15125556b33fb8adce788c28d688ddfc604e0ba6e5c479e89c8901f560cab55709156a33febb
7
- data.tar.gz: d494de1a1131a9514fa1c3bf90875ec6cdd2746a217d68c90c0d83b498d0593ecbe4388138a54a2a80e59e1cc3d7c99ced463743df3aaf542edecaf5bf16d5a6
6
+ metadata.gz: 06e464d14aa53165dd18c00d9f4de114e3d7e315a0942e64233bc418006a5d1c1b53d484d521e24c0d656020f4294a80e868f67f8ca99863f4d90d5857f20b7f
7
+ data.tar.gz: d7e4e2c021fd0289a473c4c75938bb7d2d07bbe6fec51c349a68896dac766845636ea08f4801857017c12e9062495250d5a4352eb3c96c532a045ac87150df12
data/lib/victoriafresh.rb CHANGED
@@ -9,29 +9,31 @@ require 'digest'
9
9
  # require File.dirname(__FILE__)+'/VictoriaFreSh/filemessage_pb.rb'
10
10
 
11
11
  class VictoriaFresh
12
- attr_accessor :diskFlushSize #累积了这么多的数据就向磁盘写入,以减少内存占用
13
- attr_accessor :diskFileName #向磁盘写入数据时的文件名或前缀
14
- attr_accessor :ignoreFileName # 用于指定忽略文件名列表的配置文件的名字
15
- attr_accessor :diskMultiFile #向磁盘写入时,是否要写多个文件
16
- attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
17
- attr_accessor :currentDiskFlushSuffix #当前的文件后缀。也等价于已经写入的文件片段个数
12
+ attr_accessor :diskFlushSize #累积了这么多的数据就向磁盘写入,以减少内存占用
13
+ attr_accessor :diskFileName #向磁盘写入数据时的文件名或前缀
14
+ attr_accessor :ignoreFileName # 用于指定忽略文件名列表的配置文件的名字
15
+ attr_accessor :diskMultiFile #向磁盘写入时,是否要写多个文件
16
+ attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
17
+ attr_accessor :currentDiskFlushSuffix #当前的文件后缀。也等价于已经写入的文件片段个数
18
+ attr_accessor :timestampThreshold # 文件时间戳阈值。早于这个时间戳的文件不被放入数据块
18
19
 
19
- def initialize
20
- @diskFlush=false #要向磁盘写入文件
21
- @diskFlushSize=143212 #磁盘分块大小
22
- @diskFileName='victoriafreshdata.v' #磁盘文件名
23
- @ignoreFileName=nil # 忽略文件名列表配置文件名
24
- @diskMultiFile=false #磁盘整个文件,不是多个文件
25
- @diskWriteFileObject={} #向磁盘写入文件的对象
26
- @contentString="" #内容字符串
27
- @contentPartArray=[] #内容片段数组
28
- @currentDiskFlushSuffix=0 #当前的磁盘文件后缀
29
- @bufferLength=0 #缓冲区总长度
30
- @externalDataFile={} #外部数据文件对象
31
- @nextFileIdToUse=1 # 下一个要用的文件编号。
32
- @md5FileIdMap={} # MD5 与文件编号之间的映射
33
- @fileIdPathMap={} # 文件编号与它的实际路径之间的映射
34
- end
20
+ def initialize
21
+ @diskFlush=false #要向磁盘写入文件
22
+ @diskFlushSize=143212 #磁盘分块大小
23
+ @diskFileName='victoriafreshdata.v' #磁盘文件名
24
+ @ignoreFileName=nil # 忽略文件名列表配置文件名
25
+ @diskMultiFile=false #磁盘整个文件,不是多个文件
26
+ @diskWriteFileObject={} #向磁盘写入文件的对象
27
+ @contentString="" #内容字符串
28
+ @contentPartArray=[] #内容片段数组
29
+ @currentDiskFlushSuffix=0 #当前的磁盘文件后缀
30
+ @bufferLength=0 #缓冲区总长度
31
+ @externalDataFile={} #外部数据文件对象
32
+ @nextFileIdToUse=1 # 下一个要用的文件编号。
33
+ @md5FileIdMap={} # MD5 与文件编号之间的映射
34
+ @fileIdPathMap={} # 文件编号与它的实际路径之间的映射
35
+ @timestampThreshold=0 # 默认时间戳阈值是0,所有文件都被放入数据块。
36
+ end
35
37
 
36
38
  # 计算文件内容的MD5。
37
39
  def calculateMd5(currentFileContent)
@@ -360,13 +362,9 @@ class VictoriaFresh
360
362
  current_paragraph=[] # 列表
361
363
  #陈欣
362
364
  datastore= "#{directoryPathName.expand_path}/#{@ignoreFileName}" # 配置文件路径
363
- puts "reading ignore file: #{datastore}" # Debug
364
365
 
365
366
  begin
366
367
  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
368
  if line.strip.empty? # 空行
371
369
  else # 不是空行
372
370
  current_paragraph << line.strip # 记录一行
@@ -376,128 +374,142 @@ class VictoriaFresh
376
374
  rescue Errno::ENOENT
377
375
  end
378
376
 
379
- puts "ignore list: #{current_paragraph}" # Debug
380
377
  current_paragraph
381
378
  end
379
+
380
+ def timestampTooEarly(subFile)) # 是否文件时间过早。
381
+ result=false # 结果。
382
+ directoryPathName=subFile # 获取路径对象。
383
+ #isFile=directoryPathName.file? #是否是文件。
384
+ #isSymLink=directoryPathName.symlink? #是否是符号链接
385
+ isDirectory=directoryPathName.directory? # 是否是目录。
386
+
387
+ unless isDirectory # 如果是目录就跳过
388
+ #记录时间戳:
389
+ directoryPath=directoryPathName.expand_path # 获取完整路径。
390
+ mtimeStamp=File.mtime(directoryPath) #获取时间戳
391
+
392
+ fileTimestamp=mtimeStamp.tv_sec # 获取秒数
393
+
394
+ if (fileTimestamp< @timestampThreshold) # 文件的时间戳比阈值要小,过早了
395
+ result =true # 是过早了
396
+ end # if (fileTimestamp< @timestampThreshold) # 文件的时间戳比阈值要小,过早了
397
+ end # unless isDirectory # 如果是目录就跳过
398
+
399
+ result # 返回结果
400
+ end # def timestampTooEarly(subFile)) # 是否文件时间过早。
382
401
 
383
402
  def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
384
- if (@diskFlush) #要向磁盘写入文件
385
- if (layer==0) #最外层
386
- if (@diskMultiFile) #要写多个文件
387
- else #不写多个文件
388
- @diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
389
- end #if (@diskMultiFile) #要写多个文件
390
- end #if (layer==0) #最外层
391
- end #if (@diskFlush) #要向磁盘写入文件s
403
+ if (@diskFlush) #要向磁盘写入文件
404
+ if (layer==0) #最外层
405
+ if (@diskMultiFile) #要写多个文件
406
+ else #不写多个文件
407
+ @diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
408
+ end #if (@diskMultiFile) #要写多个文件
409
+ end #if (layer==0) #最外层
410
+ end #if (@diskFlush) #要向磁盘写入文件s
411
+
412
+ packagedFile={} #创建文件消息对象。
413
+
414
+ directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
415
+
416
+ baseName=directoryPathName.basename.to_s #基本文件名。
417
+
418
+ packagedFile['name']=baseName #设置文件名。
419
+
420
+ isFile=directoryPathName.file? #是否是文件。
421
+ isSymLink=directoryPathName.symlink? #是否是符号链接
422
+
423
+ packagedFile['is_file']=isFile #设置属性,是否是文件。
424
+ packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
425
+
426
+ packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
392
427
 
393
- packagedFile={} #创建文件消息对象。
428
+ #记录时间戳:
429
+ begin #读取时间戳
430
+ mtimeStamp=File.mtime(directoryPath) #获取时间戳
394
431
 
395
- directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
432
+ packagedFile['timestamp']={} #时间戳
433
+ packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
434
+ packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
396
435
 
397
- baseName=directoryPathName.basename.to_s #基本文件名。
436
+ packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
437
+ rescue Errno::ENOENT
438
+ rescue Errno::EACCES #权限受限
439
+ end #begin #读取时间戳
398
440
 
399
- packagedFile['name']=baseName #设置文件名。
441
+ if isFile #是文件,不用再列出其子文件了。
442
+ packagedFile['file_length']=0 #记录文件的内容长度。
443
+ packagedFile['id']= nextFileId # 设置下一个文件编号
400
444
 
401
- isFile=directoryPathName.file? #是否是文件。
402
- isSymLink=directoryPathName.symlink? #是否是符号链接
445
+ #读取文件内容:
446
+ fileToReadContent=File.new(directoryPath,"rb") #创建文件。
447
+ currentFileContent=fileToReadContent.read #全部读取
448
+ fileToReadContent.close # 关闭文件
403
449
 
404
- packagedFile['is_file']=isFile #设置属性,是否是文件。
405
- packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
450
+ currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
406
451
 
407
- packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
452
+ sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
408
453
 
409
- #记录时间戳:
410
- begin #读取时间戳
411
- mtimeStamp=File.mtime(directoryPath) #获取时间戳
412
-
413
- packagedFile['timestamp']={} #时间戳
414
- packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
415
- packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
416
-
417
- packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
418
- rescue Errno::ENOENT
419
- rescue Errno::EACCES #权限受限
420
- end #begin #读取时间戳
421
-
422
- if isFile #是文件,不用再列出其子文件了。
423
- packagedFile['file_length']=0 #记录文件的内容长度。
424
- packagedFile['id']= nextFileId # 设置下一个文件编号
425
-
426
- #读取文件内容:
427
- fileToReadContent=File.new(directoryPath,"rb") #创建文件。
428
- currentFileContent=fileToReadContent.read #全部读取
429
- fileToReadContent.close # 关闭文件
430
-
431
- currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
432
-
433
- sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
434
-
435
- if sameFileId.nil? # 不存在相同的文件
436
- packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
437
-
438
- @contentPartArray << currentFileContent
439
- @bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
440
- @md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
441
- else # 存在相同的文件
442
- packagedFile['is_duplicate']=true # 是重复文件。
443
- packagedFile['same_file_id']=sameFileId # 设置相同文件的编号。
444
- end # if sameFileId.nil? # 不存在相同的文件
445
-
446
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
447
- elsif (isSymLink) #是符号链接
448
- linkTarget=directoryPathName.readlink #获取链接目标
449
-
450
- packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
451
-
452
- #读取文件内容:
453
- # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
454
- currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
455
- @contentPartArray << currentFileContent #加入数组
456
- @bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
457
-
458
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
459
- else #是目录。
460
- subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
461
-
462
- packagedFile['file_length']=0 #本目录的内容长度。
463
- packagedFile['sub_files'] = [] #加入到子文件列表中。
454
+ if sameFileId.nil? # 不存在相同的文件
455
+ packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
456
+
457
+ @contentPartArray << currentFileContent
458
+ @bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
459
+ @md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
460
+ else # 存在相同的文件
461
+ packagedFile['is_duplicate']=true # 是重复文件。
462
+ packagedFile['same_file_id']=sameFileId # 设置相同文件的编号。
463
+ end # if sameFileId.nil? # 不存在相同的文件
464
+
465
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
466
+ elsif (isSymLink) #是符号链接
467
+ linkTarget=directoryPathName.readlink #获取链接目标
464
468
 
465
- ignoreFileList=readIgnoreFileList(directoryPathName) # 读取要忽略的文件名列表。
466
-
467
- directoryPathName.each_child do |subFile| #一个个文件地处理。
468
- begin
469
- subFilebaseName=subFile.basename.to_s #基本文件名。
470
-
471
- if (ignoreFileList.include?(subFilebaseName)) # 是要忽略的文件
472
- puts "ignore #{subFile}" # 报告,忽略。
473
- else # 不忽略
474
- realPath=subFile.expand_path #获取绝对路径。
475
-
476
- packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
477
-
478
- packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
479
-
480
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
481
-
482
- subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
483
-
484
- # puts("237, content string length: #{contentString.length}") #Debug
485
-
486
- packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
487
-
488
- end
489
-
490
- rescue Errno::EMFILE # too many open Files in process
491
- puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
492
- end
493
- end #directoryPathName.each_child do |subFile| #一个个文件地处理。
494
- end #if (isFile) #是文件,不用再列出其子文件了。
469
+ packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
495
470
 
496
- # puts("300, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
471
+ #读取文件内容:
472
+ # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
473
+ currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
474
+ @contentPartArray << currentFileContent #加入数组
475
+ @bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
497
476
 
477
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
478
+ else #是目录。
479
+ subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
480
+
481
+ packagedFile['file_length']=0 #本目录的内容长度。
482
+ packagedFile['sub_files'] = [] #加入到子文件列表中。
498
483
 
499
- # puts("302, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
484
+ ignoreFileList=readIgnoreFileList(directoryPathName) # 读取要忽略的文件名列表。
500
485
 
486
+ directoryPathName.each_child do |subFile| #一个个文件地处理。
487
+ begin
488
+ subFilebaseName=subFile.basename.to_s #基本文件名。
489
+
490
+ if (ignoreFileList.include?(subFilebaseName)) # 是要忽略的文件
491
+ puts "ignore #{subFile}" # 报告,忽略。
492
+ elsif (timestampTooEarly(subFile)) # 文件时间过早。
493
+ puts "ignore #{subFile} early file" # 报告,忽略。
494
+ else # 不忽略
495
+ realPath=subFile.expand_path #获取绝对路径。
496
+
497
+ packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
498
+
499
+ packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
500
+
501
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
502
+
503
+ subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
504
+
505
+ packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
506
+ end
507
+ rescue Errno::EMFILE # too many open Files in process
508
+ puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
509
+ end
510
+ end #directoryPathName.each_child do |subFile| #一个个文件地处理。
511
+ end #if (isFile) #是文件,不用再列出其子文件了。
512
+
501
513
  contentToResult="" #要返回的内容
502
514
 
503
515
  if (layer==0) #是最外层
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.27
4
+ version: 2022.2.19
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-27 00:00:00.000000000 Z
11
+ date: 2022-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hx_cbor