old_contents: # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  # MIT License. See license.txt
  
  from __future__ import unicode_literals
  
  import frappe
  import os
  from frappe.utils import get_files_path
  from frappe.utils.file_manager import get_content_hash, get_file
  
  
  def execute():
  	for name, file_name, file_url in frappe.db.sql(
  			"""select name, file_name, file_url from `tabFile Data`
  			where file_name is not null and content_hash is null"""):
  		b = frappe.get_doc('File Data', name)
  		old_file_name = b.file_name
  		b.file_name = os.path.basename(old_file_name)
  		if old_file_name.startswith('files/') or old_file_name.startswith('/files/'):
  			b.file_url = os.path.normpath('/' + old_file_name)
  		else:
  			b.file_url = os.path.normpath('/files/' + old_file_name)
  		try:
  			_file_name, content = get_file(name)
  			b.content_hash = get_content_hash(content)
  		except IOError:
  			print 'Warning: Error processing ', name
  			_file_name = old_file_name
  			b.content_hash = None
  
  		b.save()
  
new_contents: # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  # MIT License. See license.txt
  
  from __future__ import unicode_literals
  
  import frappe
  import os
  from frappe.utils import get_files_path
  from frappe.utils.file_manager import get_content_hash, get_file
  
  
  def execute():
  	for name, file_name, file_url in frappe.db.sql(
  			"""select name, file_name, file_url from `tabFile Data`
  			where ifnull(file_name, '')!='' and ifnull(content_hash, '')=''"""):
  		b = frappe.get_doc('File Data', name)
  		old_file_name = b.file_name
  		b.file_name = os.path.basename(old_file_name)
  		if old_file_name.startswith('files/') or old_file_name.startswith('/files/'):
  			b.file_url = os.path.normpath('/' + old_file_name)
  		else:
  			b.file_url = os.path.normpath('/files/' + old_file_name)
  		try:
  			_file_name, content = get_file(name)
  			b.content_hash = get_content_hash(content)
  		except IOError:
  			print 'Warning: Error processing ', name
  			_file_name = old_file_name
  			b.content_hash = None
  
  		b.save()
  
subject: use ifnull in filemanager fix patch