VictoriaFreSh 2022.1.10 → 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 +162 -116
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 617cf53e09b7a1f7edb31b8a52c099bb65d213d95d391516cd7b59b66fb358fc
4
- data.tar.gz: 91b00d742b101d5476de3f8e9029d523c84345de992002fcf2ec40921233b3fc
3
+ metadata.gz: 8196fd50e73107e811b5e7df7ba1d81f2f42b71b346ff444f29c98e26402008b
4
+ data.tar.gz: a3a4f2dee44ff0402497c8693dd8573392ff4d1187bfd622ef78cbbf270c0553
5
5
  SHA512:
6
- metadata.gz: 9e084fbeed4401c188eadb61b625153d4e6e9ec68a31cfbbb41955542ac68e836c57af4f71e1e0fb3e3b4061b6e7f9e4196337c631a7c1a088061c860c0aaf81
7
- data.tar.gz: 6b4910d087315257024aeb1303fb8b3cd228a440039eaf63d13bc7b13bc2b84ee41246b3c725ae3426c6e15b957504beeab5232a756f75b23fcf13daa3870269
6
+ metadata.gz: 06e464d14aa53165dd18c00d9f4de114e3d7e315a0942e64233bc418006a5d1c1b53d484d521e24c0d656020f4294a80e868f67f8ca99863f4d90d5857f20b7f
7
+ data.tar.gz: d7e4e2c021fd0289a473c4c75938bb7d2d07bbe6fec51c349a68896dac766845636ea08f4801857017c12e9062495250d5a4352eb3c96c532a045ac87150df12
data/lib/victoriafresh.rb CHANGED
@@ -9,27 +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 :diskMultiFile #向磁盘写入时,是否要写多个文件
15
- attr_accessor :diskFlush #要提前磁盘写入文件,以节省内存吗?
16
- 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 # 文件时间戳阈值。早于这个时间戳的文件不被放入数据块
17
19
 
18
- def initialize
19
- @diskFlush=false #要向磁盘写入文件
20
- @diskFlushSize=143212 #磁盘分块大小
21
- @diskFileName='victoriafreshdata.v' #磁盘文件名
22
- @diskMultiFile=false #磁盘整个文件,不是多个文件
23
- @diskWriteFileObject={} #向磁盘写入文件的对象
24
- @contentString="" #内容字符串
25
- @contentPartArray=[] #内容片段数组
26
- @currentDiskFlushSuffix=0 #当前的磁盘文件后缀
27
- @bufferLength=0 #缓冲区总长度
28
- @externalDataFile={} #外部数据文件对象
29
- @nextFileIdToUse=1 # 下一个要用的文件编号。
30
- @md5FileIdMap={} # MD5 与文件编号之间的映射
31
- @fileIdPathMap={} # 文件编号与它的实际路径之间的映射
32
- 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
33
37
 
34
38
  # 计算文件内容的MD5。
35
39
  def calculateMd5(currentFileContent)
@@ -353,117 +357,159 @@ class VictoriaFresh
353
357
  end #if (@diskFlush) #要做磁盘写入
354
358
  end #contentString= assessDiskFlush(contentString) #考虑是否要向磁盘先输出内容
355
359
 
356
- def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
357
- if (@diskFlush) #要向磁盘写入文件
358
- if (layer==0) #最外层
359
- if (@diskMultiFile) #要写多个文件
360
- else #不写多个文件
361
- @diskWriteFileObject=File.new(@diskFileName, 'wb') #打开文件
362
- end #if (@diskMultiFile) #要写多个文件
363
- end #if (layer==0) #最外层
364
- end #if (@diskFlush) #要向磁盘写入文件s
360
+ # 读取要忽略的文件名列表。
361
+ def readIgnoreFileList (directoryPathName)
362
+ current_paragraph=[] # 列表
363
+ #陈欣
364
+ datastore= "#{directoryPathName.expand_path}/#{@ignoreFileName}" # 配置文件路径
365
+
366
+ begin
367
+ File.foreach(datastore).with_index do |line, _line_num|
368
+ if line.strip.empty? # 空行
369
+ else # 不是空行
370
+ current_paragraph << line.strip # 记录一行
371
+ end # if line.strip.empty? # 空行
372
+ end # File&.foreach(datastore).with_index do |line, _line_num|
373
+
374
+ rescue Errno::ENOENT
375
+ end
376
+
377
+ current_paragraph
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) #获取时间戳
365
391
 
366
- packagedFile={} #创建文件消息对象。
392
+ fileTimestamp=mtimeStamp.tv_sec # 获取秒数
367
393
 
368
- packagedFile['sub_files'] = [] #加入到子文件列表中。
394
+ if (fileTimestamp< @timestampThreshold) # 文件的时间戳比阈值要小,过早了
395
+ result =true # 是过早了
396
+ end # if (fileTimestamp< @timestampThreshold) # 文件的时间戳比阈值要小,过早了
397
+ end # unless isDirectory # 如果是目录就跳过
398
+
399
+ result # 返回结果
400
+ end # def timestampTooEarly(subFile)) # 是否文件时间过早。
401
+
402
+ def checkOnce(directoryPath, startIndex=0, layer=0) #打包一个目录树。
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 #设置属性,是否是符号链接
369
427
 
370
- directoryPathName=Pathname.new(directoryPath) #构造路径名字对象。
428
+ #记录时间戳:
429
+ begin #读取时间戳
430
+ mtimeStamp=File.mtime(directoryPath) #获取时间戳
371
431
 
372
- baseName=directoryPathName.basename.to_s #基本文件名。
432
+ packagedFile['timestamp']={} #时间戳
433
+ packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
434
+ packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
373
435
 
374
- packagedFile['name']=baseName #设置文件名。
436
+ packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
437
+ rescue Errno::ENOENT
438
+ rescue Errno::EACCES #权限受限
439
+ end #begin #读取时间戳
375
440
 
376
- isFile=directoryPathName.file? #是否是文件。
377
- isSymLink=directoryPathName.symlink? #是否是符号链接
441
+ if isFile #是文件,不用再列出其子文件了。
442
+ packagedFile['file_length']=0 #记录文件的内容长度。
443
+ packagedFile['id']= nextFileId # 设置下一个文件编号
378
444
 
379
- packagedFile['is_file']=isFile #设置属性,是否是文件。
380
- packagedFile['file_start_index']=startIndex #记录文件内容的开始位置。
445
+ #读取文件内容:
446
+ fileToReadContent=File.new(directoryPath,"rb") #创建文件。
447
+ currentFileContent=fileToReadContent.read #全部读取
448
+ fileToReadContent.close # 关闭文件
381
449
 
382
- packagedFile['is_symlink']=isSymLink #设置属性,是否是符号链接
450
+ currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
383
451
 
384
- puts directoryPath #Dbug.
452
+ sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
385
453
 
386
- #记录时间戳:
387
- begin #读取时间戳
388
- mtimeStamp=File.mtime(directoryPath) #获取时间戳
389
-
390
- packagedFile['timestamp']={} #时间戳
391
- packagedFile['timestamp']['seconds']=mtimeStamp.tv_sec #设置秒数
392
- packagedFile['timestamp']['nanos']=mtimeStamp.tv_nsec #设置纳秒数
393
-
394
- packagedFile['permission']=(File.stat(directoryPath).mode & 07777 ) #设置权限信息
395
- rescue Errno::ENOENT
396
- rescue Errno::EACCES #权限受限
397
- end #begin #读取时间戳
398
-
399
- if isFile #是文件,不用再列出其子文件了。
400
- packagedFile['file_length']=directoryPathName.size #记录文件的内容长度。
401
- packagedFile['id']= nextFileId # 设置下一个文件编号
402
-
403
- #读取文件内容:
404
- fileToReadContent=File.new(directoryPath,"rb") #创建文件。
405
- currentFileContent=fileToReadContent.read #全部读取
406
-
407
- currentContentMd5=calculateMd5(currentFileContent) # 计算文件内容的MD5。
408
-
409
- sameFileId=@md5FileIdMap[currentContentMd5] # 尝试寻找对应的相同文件的编号。
410
-
411
- if sameFileId.nil? # 不存在相同的文件
412
- @contentPartArray << currentFileContent
413
- @bufferLength=@bufferLength+ currentFileContent.length #记录缓冲区总长度
414
- @md5FileIdMap[currentContentMd5]=packagedFile['id'] # 尝试寻找对应的相同文件的编号。
415
- else # 存在相同的文件
416
- packagedFile['is_duplicate']=true # 是重复文件。
417
- packagedFile['same_file_id']=sameFileId # 设置相同文件的编号。
418
- end # if sameFileId.nil? # 不存在相同的文件
419
-
420
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
421
- elsif (isSymLink) #是符号链接
422
- linkTarget=directoryPathName.readlink #获取链接目标
423
-
424
- packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
425
-
426
- #读取文件内容:
427
- # fileToReadContent=File.new(directoryPath,"rb") #创建文件。
428
- currentFileContent=StringIO.new(linkTarget.to_s).binmode.read #全部读取。
429
- @contentPartArray << currentFileContent #加入数组
430
- @bufferLength=@bufferLength + currentFileContent.length #记录缓冲区总长度
431
-
432
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
433
- else #是目录。
434
- subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
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 #获取链接目标
435
468
 
436
- packagedFile['file_length']=0 #本目录的内容长度。
437
-
438
- puts "Listing for #{directoryPathName}" # Debug
439
-
440
- directoryPathName.each_child do |subFile| #一个个文件地处理。
441
- begin
442
- realPath=subFile.expand_path #获取绝对路径。
443
-
444
- packagedSubFile,subFileContent=checkOnce(realPath,subFileStartIndex, layer+1) #打包这个子文件。
445
-
446
- packagedFile['sub_files'] << packagedSubFile #加入到子文件列表中。
447
-
448
- assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
449
-
450
-
451
- subFileStartIndex+=packagedSubFile['file_length'] #记录打包的子文件的长度,更新下一个要打包的子文件的起始位置。
452
-
453
- # puts("237, content string length: #{contentString.length}") #Debug
454
-
455
- packagedFile['file_length']+=packagedSubFile['file_length'] #随着子文件的打包而更新本目录的总长度。
456
- rescue Errno::EMFILE # File not exist
457
- puts "Rescued by Errno::EMFILE statement. #{subFile}" #报告错误
458
- end
459
- end #directoryPathName.each_child do |subFile| #一个个文件地处理。
460
- end #if (isFile) #是文件,不用再列出其子文件了。
469
+ packagedFile['file_length']=linkTarget.to_s.bytesize #记录文件的内容长度。
461
470
 
462
- # 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 #记录缓冲区总长度
463
476
 
477
+ assessDiskFlush(layer) #考虑是否要向磁盘先输出内容
478
+ else #是目录。
479
+ subFileStartIndex=startIndex #子文件的起始位置,以此目录的起始位置为基准。
480
+
481
+ packagedFile['file_length']=0 #本目录的内容长度。
482
+ packagedFile['sub_files'] = [] #加入到子文件列表中。
464
483
 
465
- # puts("302, contentString: #{contentString}, nil?: #{contentString.nil?}, direcotry path: #{directoryPath}, layer: #{layer}") #Debug
484
+ ignoreFileList=readIgnoreFileList(directoryPathName) # 读取要忽略的文件名列表。
466
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
+
467
513
  contentToResult="" #要返回的内容
468
514
 
469
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.10
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-08 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