Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/FrameRange.i
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@
}
}

%extend sequenceParser::FrameRangesSubView
{
%pythoncode
{
def __iter__(self):
return PyFrameRangesConstIterator(self.begin().previous(), self.end())
def __str__(self):
return self.string()
}
}

#endif
27 changes: 17 additions & 10 deletions src/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,25 @@ std::vector<Item> Item::explode()
EType getTypeFromPath( const boost::filesystem::path& path )
{
if( bfs::is_symlink( path ) )
{
return eTypeLink;
}
if( bfs::is_regular_file( path ) )
{
return eTypeFile;
}
return eTypeLink;
}
if( bfs::is_regular_file( path ) )
{
return eTypeFile;
}
if( bfs::is_directory( path ) )
{
return eTypeFolder;
}
return eTypeUndefined;
{
return eTypeFolder;
}
return eTypeUndefined;
}


EType getTypeFromPath( const std::string& pathStr )
{
const boost::filesystem::path path( pathStr );
return getTypeFromPath(path);
}


Expand Down
11 changes: 11 additions & 0 deletions src/Item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class Item
_path /= sequence.getStandardPattern();
}

Item( const Sequence& sequence, const std::string& folder )
: _type(eTypeSequence)
, _path(folder)
, _sequence(sequence)
{
_path /= sequence.getStandardPattern();
}

EType getType() const { return _type; }

std::string getAbsoluteFilepath() const { return _path.string(); }
Expand Down Expand Up @@ -92,7 +100,10 @@ class Item
};


#ifndef SWIG
EType getTypeFromPath( const boost::filesystem::path& path );
#endif
EType getTypeFromPath( const std::string& pathStr );


std::ostream& operator<<( std::ostream& os, const Item& item );
Expand Down
99 changes: 95 additions & 4 deletions src/ItemStat.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "ItemStat.hpp"
#include "system.hpp"

#include <boost/filesystem/operations.hpp>

#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>


namespace bfs = boost::filesystem;
Expand Down Expand Up @@ -65,6 +65,45 @@ ItemStat::ItemStat( const Item& item, const bool approximative )
}
}

std::string ItemStat::getUserName() const
{
#ifdef __UNIX__
passwd* user = getpwuid(userId);
if(user == NULL)
return std::string("unknown");
return std::string(user->pw_name ? user->pw_name : "unknown");
#else
return std::string("not implemented");
#endif
}

std::string ItemStat::getGroupName() const
{
#ifdef __UNIX__
group* group = getgrgid(groupId);
if(group == NULL)
return std::string("unknown");
return std::string(group->gr_name ? group->gr_name : "unknown");
#else
return std::string("not implemented");
#endif
}

#ifdef __UNIX__
void ItemStat::setPermissions( const mode_t& protection )
{
ownerCanRead = protection & S_IRUSR;
ownerCanWrite = protection & S_IWUSR;
ownerCanExecute = protection & S_IXUSR;
groupCanRead = protection & S_IRGRP;
groupCanWrite = protection & S_IWGRP;
groupCanExecute = protection & S_IXGRP;
otherCanRead = protection & S_IROTH;
otherCanWrite = protection & S_IWOTH;
otherCanExecute = protection & S_IXOTH;
}
#endif

void ItemStat::statLink( const boost::filesystem::path& path )
{
boost::system::error_code errorCode;
Expand All @@ -87,8 +126,11 @@ void ItemStat::statLink( const boost::filesystem::path& path )
accessTime = statInfos.st_atime;
creationTime = statInfos.st_ctime;
size = statInfos.st_size;
minSize = size;
maxSize = size;
// size on hard-drive (takes hardlinks into account)
sizeOnDisk = (statInfos.st_blocks / nbHardLinks) * 512;
setPermissions(statInfos.st_mode);
#else
fullNbHardLinks = nbHardLinks = 1;
deviceId = 0;
Expand All @@ -112,9 +154,20 @@ void ItemStat::setDefaultValues(){
creationTime = 0;
sizeOnDisk = 0;
size = 0;
minSize = 0;
maxSize = 0;
realSize = 0;
fullNbHardLinks = 0;
modificationTime = -1;
ownerCanRead = false;
ownerCanWrite = false;
ownerCanExecute = false;
groupCanRead = false;
groupCanWrite = false;
groupCanExecute = false;
otherCanRead = false;
otherCanWrite = false;
otherCanExecute = false;
}

void ItemStat::statFolder( const boost::filesystem::path& path )
Expand All @@ -141,8 +194,11 @@ void ItemStat::statFolder( const boost::filesystem::path& path )
accessTime = statInfos.st_atime;
creationTime = statInfos.st_ctime;
size = statInfos.st_size;
minSize = size;
maxSize = size;
// size on hard-drive (takes hardlinks into account)
sizeOnDisk = statInfos.st_blocks * 512;
setPermissions(statInfos.st_mode);
#else
deviceId = 0;
inodeId = 0;
Expand All @@ -164,6 +220,8 @@ void ItemStat::statFile( const boost::filesystem::path& path )
boost::system::error_code errorCode;
fullNbHardLinks = nbHardLinks = bfs::hard_link_count( path, errorCode );
size = bfs::file_size( path, errorCode );
minSize = size;
maxSize = size;
modificationTime = bfs::last_write_time( path, errorCode );
int stat_status = -1;

Expand All @@ -183,8 +241,8 @@ void ItemStat::statFile( const boost::filesystem::path& path )
accessTime = statInfos.st_atime;
creationTime = statInfos.st_ctime;
// size on hard-drive (takes hardlinks into account)
sizeOnDisk = (statInfos.st_blocks / nbHardLinks) * 512;

sizeOnDisk = (statInfos.st_blocks / nbHardLinks) * 512;
setPermissions(statInfos.st_mode);
#else
deviceId = 0;
inodeId = 0;
Expand Down Expand Up @@ -219,6 +277,7 @@ void ItemStat::statSequence( const Item& item, const bool approximative )
userId = statInfos.st_uid;
groupId = statInfos.st_gid;
accessTime = statInfos.st_atime;
setPermissions(statInfos.st_mode);
#else
deviceId = 0;
inodeId = 0;
Expand All @@ -230,6 +289,8 @@ void ItemStat::statSequence( const Item& item, const bool approximative )
modificationTime = 0;
fullNbHardLinks = 0;
size = 0;
minSize = 0;
maxSize = 0;
realSize = 0;
sizeOnDisk = 0;
creationTime = 0;
Expand All @@ -250,14 +311,44 @@ void ItemStat::statSequence( const Item& item, const bool approximative )

ItemStat fileStat(type, filepath);

// use the most restrictive permissions in the sequence
#ifdef __UNIX__
// user
if( ownerCanRead && ! fileStat.ownerCanRead)
ownerCanRead = false;
if( ownerCanWrite && ! fileStat.ownerCanWrite)
ownerCanWrite = false;
if( ownerCanExecute && ! fileStat.ownerCanExecute)
ownerCanExecute = false;
// group
if( groupCanRead && ! fileStat.groupCanRead)
groupCanRead = false;
if( groupCanWrite && ! fileStat.groupCanWrite)
groupCanWrite = false;
if( groupCanExecute && ! fileStat.groupCanExecute)
groupCanExecute = false;
// other
if( otherCanRead && ! fileStat.otherCanRead)
otherCanRead = false;
if( otherCanWrite && ! fileStat.otherCanWrite)
otherCanWrite = false;
if( otherCanExecute && ! fileStat.otherCanExecute)
otherCanExecute = false;
#endif

// use the latest modification date in the sequence
if( fileStat.modificationTime > modificationTime )
modificationTime = fileStat.modificationTime;
if( creationTime == 0 || creationTime > fileStat.creationTime )
creationTime = fileStat.creationTime;

// compute sizes
fullNbHardLinks += fileStat.fullNbHardLinks;
size += fileStat.size;
if( minSize == 0 || minSize > fileStat.size )
minSize = fileStat.size;
if( maxSize == 0 || maxSize < fileStat.size )
maxSize = fileStat.size;
realSize += fileStat.realSize;
sizeOnDisk += fileStat.sizeOnDisk;
}
Expand Down
22 changes: 22 additions & 0 deletions src/ItemStat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include "Item.hpp"
#include "common.hpp"
#include "system.hpp"

#ifdef __UNIX__
#include <sys/types.h>
#endif


namespace sequenceParser {
Expand All @@ -13,12 +18,18 @@ class ItemStat
ItemStat( const Item& item, const bool approximative=true );
ItemStat( const EType& type, const boost::filesystem::path& path, const bool approximative=true );

std::string getUserName() const;
std::string getGroupName() const;

private:
void statFolder( const boost::filesystem::path& path );
void statFile( const boost::filesystem::path& path );
void statSequence( const Item& item, const bool approximative );
void statLink( const boost::filesystem::path& path );
void setDefaultValues();
#ifdef __UNIX__
void setPermissions( const mode_t& protection );
#endif

public:
long long deviceId;
Expand All @@ -28,11 +39,22 @@ class ItemStat
long long userId;
long long groupId;
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;
bool ownerCanRead;
bool ownerCanWrite;
bool ownerCanExecute;
bool groupCanRead;
bool groupCanWrite;
bool groupCanExecute;
bool otherCanRead;
bool otherCanWrite;
bool otherCanExecute;
};

}
Expand Down
39 changes: 12 additions & 27 deletions src/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,48 +318,44 @@ EPattern Sequence::checkPattern( const std::string& pattern, const EDetection de
* and init internal values.
* @param[in] pattern
* @param[in] accept
* @param[out] prefix
* @param[out] suffix
* @param[out] padding
* @param[out] strictPadding
*/
bool Sequence::retrieveInfosFromPattern( const std::string& filePattern, const EPattern& accept, std::string& prefix, std::string& suffix, std::size_t& padding, bool& strictPadding ) const
bool Sequence::initFromPattern( const std::string& filePattern, const EPattern& accept )
{
boost::cmatch matches;
//std::cout << filePattern << " / " << prefix << " + " << padding << " + " << suffix << std::endl;
//std::cout << filePattern << " / " << _prefix << " + " << _padding << " + " << _suffix << std::endl;
if( ( accept & ePatternStandard ) && regex_match( filePattern.c_str(), matches, regexPatternStandard ) )
{
std::string paddingStr( matches[2].first, matches[2].second );
padding = paddingStr.size();
strictPadding = ( paddingStr[0] == '#' );
_padding = paddingStr.size();
_strictPadding = ( paddingStr[0] == '#' );
}
else if( ( accept & ePatternCStyle ) && regex_match( filePattern.c_str(), matches, regexPatternCStyle ) )
{
std::string paddingStr( matches[2].first, matches[2].second );
padding = paddingStr.size() == 0 ? 0 : boost::lexical_cast<std::size_t > ( paddingStr ); // if no padding value: %d -> padding = 0
strictPadding = false;
_padding = paddingStr.size() == 0 ? 0 : boost::lexical_cast<std::size_t > ( paddingStr ); // if no _padding value: %d -> _padding = 0
_strictPadding = false;
}
else if( ( accept & ePatternFrame ) && regex_match( filePattern.c_str(), matches, regexPatternFrame ) )
{
std::string frame( matches[2].first, matches[2].second );
// Time t = boost::lexical_cast<Time>( frame );
padding = frame.size();
strictPadding = false;
_padding = frame.size();
_strictPadding = false;
}
else if( ( accept & ePatternFrameNeg ) && regex_match( filePattern.c_str(), matches, regexPatternFrameNeg ) )
{
std::string frame( matches[2].first, matches[2].second );
// Time t = boost::lexical_cast<Time>( frame );
padding = frame.size();
strictPadding = false;
_padding = frame.size();
_strictPadding = false;
}
else
{
// this is a file, not a sequence
return false;
}
prefix = std::string( matches[1].first, matches[1].second );
suffix = std::string( matches[3].first, matches[3].second );
_prefix = std::string( matches[1].first, matches[1].second );
_suffix = std::string( matches[3].first, matches[3].second );
return true;
}

Expand All @@ -374,17 +370,6 @@ void Sequence::init( const std::string& prefix, const std::size_t padding, const
_strictPadding = strictPadding;
}


bool Sequence::initFromPattern( const std::string& pattern, const std::vector<FrameRange>& frameRanges, const EPattern accept )
{
if( !retrieveInfosFromPattern( pattern, accept, _prefix, _suffix, _padding, _strictPadding ) )
return false; // not regognize as a pattern, maybe a still file
_ranges.clear();
_ranges = frameRanges;
return true;
}


std::vector<boost::filesystem::path> Sequence::getFiles() const
{
std::vector<boost::filesystem::path> allPaths;
Expand Down
Loading