Skip to content

Commit

Permalink
uncomitted staged changes: also count number of files in disk usage c…
Browse files Browse the repository at this point in the history
…omputation + a fix
  • Loading branch information
proycon committed Aug 21, 2019
1 parent 8decd59 commit 47549a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions clam/clamservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def getprojects(user):
if os.path.isdir(f):
d = datetime.datetime.fromtimestamp(os.stat(f)[8])
project = os.path.basename(f)
projectsize = Project.getdiskusage(user,project )
projectsize, filecount = Project.getdiskusage(user,project )
totalsize += projectsize
projects.append( ( project , d.strftime("%Y-%m-%d %H:%M:%S"), round(projectsize,2), Project.simplestatus(project,user) ) )
with io.open(os.path.join(path,'.index'),'w',encoding='utf-8') as f:
Expand Down Expand Up @@ -629,10 +629,10 @@ def getdiskusage(user, project):
with open(os.path.join(path,'.du'),'r') as f:
return float(f.read().strip())
else:
size = computediskusage(path)
size, count = computediskusage(path)
with open(os.path.join(path,'.du'),'w') as f:
f.write(str(size))
return size
return size, count

@staticmethod
def create(project, credentials): #pylint: disable=too-many-return-statements
Expand Down
2 changes: 1 addition & 1 deletion clam/common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ def xml(self, indent = ""):
else:
method = ""
if self.allowanonymous:
allowanonymous = "allowanoymous=\"yes\""
allowanonymous = "allowanonymous=\"yes\""
else:
allowanonymous = ""
xml = indent + "<action id=\"" + self.id + "\" " + method + " name=\"" + self.name + "\" description=\"" +self.description + "\" mimetype=\"" + self.mimetype + "\" " + allowanonymous + ">\n"
Expand Down
4 changes: 3 additions & 1 deletion clam/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def globsymlinks(pattern, recursion=True):

def computediskusage(path):
total_size = 0
total_files = 0
for dirpath, dirnames, filenames in os.walk(path): #pylint: disable=unused-variable
for f in filenames:
fp = os.path.join(dirpath, f)
try:
total_size += os.path.getsize(fp)
total_files += 1
except:
#may happen in case of dangling symlinks
pass
return total_size / 1024 / 1024 #MB
return total_size / 1024 / 1024, total_files #MB


def setlog(log):
Expand Down

0 comments on commit 47549a5

Please sign in to comment.