summary refs log tree commit diff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2011-01-12 21:07:56 +0100
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>2011-01-12 21:07:56 +0100
commit0fe64c04f8ae57ace54404a8b8bfb5deff552e2d (patch)
tree58524724d1a9c2370b3f378bc2bf8340ac01c7c6
parent0d8d9877ad7dc7ba893f7e37382add01a01c3d0a (diff)
downloadyoutube-dl-0fe64c04f8ae57ace54404a8b8bfb5deff552e2d.tar.gz
youtube-dl-0fe64c04f8ae57ace54404a8b8bfb5deff552e2d.tar.xz
youtube-dl-0fe64c04f8ae57ace54404a8b8bfb5deff552e2d.zip
Make the self-updating function a bit more robust
-rwxr-xr-xyoutube-dl24
1 files changed, 15 insertions, 9 deletions
diff --git a/youtube-dl b/youtube-dl
index 32e334ce4..443bb211b 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -2296,20 +2296,26 @@ if __name__ == '__main__':
 		import getpass
 		import optparse
 
-		# Function to update the program file with the latest version from bitbucket.org
+		# Function to update the program file with the latest version from the repository.
 		def update_self(downloader, filename):
 			# Note: downloader only used for options
-			if not os.access (filename, os.W_OK):
+			if not os.access(filename, os.W_OK):
 				sys.exit('ERROR: no write permissions on %s' % filename)
 
 			downloader.to_screen('Updating to latest stable version...')
-			latest_url = 'http://github.com/rg3/youtube-dl/raw/master/LATEST_VERSION'
-			latest_version = urllib.urlopen(latest_url).read().strip()
-			prog_url = 'http://github.com/rg3/youtube-dl/raw/%s/youtube-dl' % latest_version
-			newcontent = urllib.urlopen(prog_url).read()
-			stream = open(filename, 'w')
-			stream.write(newcontent)
-			stream.close()
+			try:
+				latest_url = 'http://github.com/rg3/youtube-dl/raw/master/LATEST_VERSION'
+				latest_version = urllib.urlopen(latest_url).read().strip()
+				prog_url = 'http://github.com/rg3/youtube-dl/raw/%s/youtube-dl' % latest_version
+				newcontent = urllib.urlopen(prog_url).read()
+			except (IOError, OSError), err:
+				sys.exit('ERROR: unable to download latest version')
+			try:
+				stream = open(filename, 'w')
+				stream.write(newcontent)
+				stream.close()
+			except (IOError, OSError), err:
+				sys.exit('ERROR: unable to overwrite current version')
 			downloader.to_screen('Updated to version %s' % latest_version)
 
 		# Parse command line