2009-10-23 12:56:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-10-23
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-10-23 12:56:52 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-10-23 12:56:52 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-10-23 12:56:52 +00:00
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
from hsutil import io
|
|
|
|
from hsutil.misc import nonone
|
|
|
|
|
2009-12-30 10:37:57 +00:00
|
|
|
from core import fs
|
2009-10-23 12:56:52 +00:00
|
|
|
|
|
|
|
class Bundle(fs.File):
|
|
|
|
"""This class is for Mac OSX bundles (.app). Bundles are seen by the OS as
|
|
|
|
normal directories, but I don't want that in dupeGuru. I want dupeGuru
|
|
|
|
to see them as files.
|
|
|
|
"""
|
|
|
|
def _read_info(self, field):
|
2010-08-13 07:26:38 +00:00
|
|
|
if field in ('size', 'mtime'):
|
2009-10-23 12:56:52 +00:00
|
|
|
files = fs.get_all_files(self.path)
|
|
|
|
size = sum((file.size for file in files), 0)
|
|
|
|
self.size = size
|
|
|
|
stats = io.stat(self.path)
|
|
|
|
self.mtime = nonone(stats.st_mtime, 0)
|
|
|
|
elif field in ('md5', 'md5partial'):
|
|
|
|
# What's sensitive here is that we must make sure that subfiles'
|
|
|
|
# md5 are always added up in the same order, but we also want a
|
|
|
|
# different md5 if a file gets moved in a different subdirectory.
|
|
|
|
def get_dir_md5_concat():
|
|
|
|
files = fs.get_all_files(self.path)
|
|
|
|
files.sort(key=lambda f:f.path)
|
|
|
|
md5s = [getattr(f, field) for f in files]
|
2010-08-11 14:39:06 +00:00
|
|
|
return b''.join(md5s)
|
2009-10-23 12:56:52 +00:00
|
|
|
|
|
|
|
md5 = hashlib.md5(get_dir_md5_concat())
|
|
|
|
digest = md5.digest()
|
|
|
|
setattr(self, field, digest)
|