Skip to content

Commit

Permalink
ItemStat: change creationTime to correct name and calculate lastChang…
Browse files Browse the repository at this point in the history
…e time for folder

ItemStat: renamed creationTime to lastChangeTime (and fix its compute)
  • Loading branch information
cchampet committed May 20, 2016
2 parents 80da80e + 7b49a27 commit 262391f
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/sequenceParser/ItemStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void ItemStat::statLink( const boost::filesystem::path& path )
userId = statInfos.st_uid;
groupId = statInfos.st_gid;
accessTime = statInfos.st_atime;
creationTime = statInfos.st_ctime;
lastChangeTime = statInfos.st_ctime;
size = statInfos.st_size;
minSize = size;
maxSize = size;
Expand All @@ -140,7 +140,7 @@ void ItemStat::statLink( const boost::filesystem::path& path )
userId = 0;
groupId = 0;
accessTime = 0;
creationTime = 0;
lastChangeTime = 0;
sizeOnDisk = 0;
size = 0;
#endif
Expand All @@ -153,7 +153,7 @@ void ItemStat::setDefaultValues(){
userId = 0;
groupId = 0;
accessTime = 0;
creationTime = 0;
lastChangeTime = -1;
sizeOnDisk = 0;
size = 0;
minSize = 0;
Expand Down Expand Up @@ -194,7 +194,7 @@ void ItemStat::statFolder( const boost::filesystem::path& path )
userId = statInfos.st_uid;
groupId = statInfos.st_gid;
accessTime = statInfos.st_atime;
creationTime = statInfos.st_ctime;
lastChangeTime = statInfos.st_ctime;
size = statInfos.st_size;
minSize = size;
maxSize = size;
Expand All @@ -207,7 +207,7 @@ void ItemStat::statFolder( const boost::filesystem::path& path )
userId = 0;
groupId = 0;
accessTime = 0;
creationTime = 0;
lastChangeTime = 0;
sizeOnDisk = 0;
size = 0;
#endif
Expand Down Expand Up @@ -241,7 +241,7 @@ void ItemStat::statFile( const boost::filesystem::path& path )
userId = statInfos.st_uid;
groupId = statInfos.st_gid;
accessTime = statInfos.st_atime;
creationTime = statInfos.st_ctime;
lastChangeTime = statInfos.st_ctime;
// size on hard-drive (takes hardlinks into account)
sizeOnDisk = (statInfos.st_blocks / nbHardLinks) * 512;
setPermissions(statInfos.st_mode);
Expand All @@ -251,7 +251,7 @@ void ItemStat::statFile( const boost::filesystem::path& path )
userId = 0;
groupId = 0;
accessTime = 0;
creationTime = 0;
lastChangeTime = 0;
sizeOnDisk = 0;
#endif

Expand Down Expand Up @@ -295,7 +295,7 @@ void ItemStat::statSequence( const Item& item, const bool approximative )
maxSize = 0;
realSize = 0;
sizeOnDisk = 0;
creationTime = 0;
lastChangeTime = 0;

const Sequence& seq = item.getSequence();

Expand Down Expand Up @@ -341,8 +341,8 @@ void ItemStat::statSequence( const Item& item, const bool approximative )
// use the latest modification date in the sequence
if( fileStat.modificationTime > modificationTime )
modificationTime = fileStat.modificationTime;
if( creationTime == 0 || creationTime > fileStat.creationTime )
creationTime = fileStat.creationTime;
if( lastChangeTime == 0 || lastChangeTime < fileStat.lastChangeTime )
lastChangeTime = fileStat.lastChangeTime;

// compute sizes
fullNbHardLinks += fileStat.fullNbHardLinks;
Expand Down
33 changes: 24 additions & 9 deletions src/sequenceParser/ItemStat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,35 @@ class ItemStat
#endif

public:
long long deviceId;
unsigned int inodeId;
double nbHardLinks;
long long fullNbHardLinks;
long long userId;
long long groupId;
// See the following doc to get file status on UNIX system
// See http://linux.die.net/man/2/stat
long long deviceId; /// ID of device containing file
unsigned int inodeId; /// inode number
double nbHardLinks; /// number of hard links
long long fullNbHardLinks; /// total number of hard links in a sequence (otherwise, same value as nbHardLinks)
long long userId; /// user ID of owner
long long groupId; /// group ID of owner

/**
* @brief total size, in bytes
* @note The size of a symbolic link is the length of the pathname it contains, without a terminating null byte
*/
long long size;
long long minSize; /// size of the smallest file in the sequence (otherwise, same value as size)
long long maxSize; /// size of the biggest file in the sequence (otherwise, same value as size)
long long realSize; /// size (takes hardlinks into account)
long long sizeOnDisk; /// size on hard-drive (takes hardlinks into account)
long long accessTime;
long long modificationTime;
long long creationTime;

long long accessTime; /// time of last access
long long modificationTime; /// time of last modification
/**
* @brief Time of last status change
* @note In case of rsync command with preserve times,
* the modification time is the same as remote file and the lastChangeTime is the local time
*/
long long lastChangeTime;

// permissions
bool ownerCanRead;
bool ownerCanWrite;
bool ownerCanExecute;
Expand Down
8 changes: 8 additions & 0 deletions test/pyTest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def createFile(path, filename):
open(ff, 'w').close()


def createFolder(path, folderName):
"""
Create an empty folder.
"""
dd = os.path.join(path, folderName)
os.mkdir(dd)


def getSequencesFromPath(path, detectionOptions, filters=[]):
"""
Get a list of sequences found thanks to a browse with the given parameters.
Expand Down
118 changes: 118 additions & 0 deletions test/pyTest/testStat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import time
import tempfile
import os
import shutil

from pySequenceParser import sequenceParser as seq
from . import createFile, createFolder, getSequencesFromPath

from nose.tools import *

root_path = ''


def setUp():
global root_path
root_path = tempfile.mkdtemp()

# create files
files_to_create = [
"plop.txt",
"foo.001.png",
"foo.002.png",
"foo.003.png",
]
for f in files_to_create:
createFile(root_path, f)

# create folder
createFolder(root_path, "dir1")

# create sym link
os.symlink(os.path.join(root_path, "plop.txt"), os.path.join(root_path, "plop_sym_link.txt"))


def tearDown():
global root_path
shutil.rmtree(root_path)


def testFileStat():
"""
Check stats of a single file.
- 1 hard link
- size = minSize = maxSize = realSize = sizeOnDisk
- check the different times
"""
itemFile = seq.Item(seq.eTypeFile, os.path.join(root_path, "plop.txt"))
itemStat = seq.ItemStat(itemFile)
# nb hard links
assert_equals(itemStat.nbHardLinks, 1)
assert_equals(itemStat.fullNbHardLinks, 1)
# check size
assert_equals(itemStat.size, itemStat.minSize)
assert_equals(itemStat.size, itemStat.maxSize)
assert_equals(itemStat.realSize, itemStat.size / itemStat.nbHardLinks)
assert_greater_equal(itemStat.sizeOnDisk, itemStat.size)
# time
currentTime = round(time.time())
assert_less_equal(itemStat.accessTime, currentTime)
assert_less_equal(itemStat.modificationTime, currentTime)
assert_less_equal(itemStat.lastChangeTime, currentTime)


def testSymLinkStat():
"""
Check stats of a folder.
- 1 hard link
- sizes
"""
src = os.path.join(root_path, "plop_sym_link.txt")
dst = os.path.join(root_path, "plop.txt")
itemFile = seq.Item(seq.eTypeLink, src)
itemStat = seq.ItemStat(itemFile)
# nb hard links
assert_equals(itemStat.nbHardLinks, 1)
assert_equals(itemStat.fullNbHardLinks, 1)
# check size
assert_equals(itemStat.size, len(dst))
assert_equals(itemStat.size, itemStat.minSize)
assert_equals(itemStat.size, itemStat.maxSize)
assert_equals(itemStat.realSize, itemStat.size / itemStat.nbHardLinks)


def testFolderStat():
"""
Check stats of a folder.
- 2 hard links (. and ..)
- sizes
"""
itemFile = seq.Item(seq.eTypeFile, os.path.join(root_path, "dir1"))
itemStat = seq.ItemStat(itemFile)
# nb hard links
assert_equals(itemStat.nbHardLinks, 2)
assert_equals(itemStat.fullNbHardLinks, 2)
# check size
assert_equals(itemStat.size, itemStat.minSize)
assert_equals(itemStat.size, itemStat.maxSize)
#assert_equals(itemStat.realSize, itemStat.size) # 0L != -1L
assert_greater_equal(itemStat.sizeOnDisk, itemStat.size)


def testSequenceStat():
"""
Check stats of a sequence.
- number of hard links
- sizes
"""
itemSequence = getSequencesFromPath(root_path, seq.eDetectionDefault)[0]
nbFilesInSequence = itemSequence.getSequence().getNbFiles()
itemStat = seq.ItemStat(itemSequence)
# nb hard links
assert_equals(itemStat.nbHardLinks, 1)
assert_equals(itemStat.fullNbHardLinks, 3)
# check size
assert_equals(itemStat.size, itemStat.minSize * nbFilesInSequence)
assert_equals(itemStat.size, itemStat.maxSize * nbFilesInSequence)
assert_equals(itemStat.realSize, itemStat.size / itemStat.nbHardLinks)
assert_greater_equal(itemStat.sizeOnDisk, itemStat.size)

0 comments on commit 262391f

Please sign in to comment.