Permalink
Browse files

making sure the same friendly name cannot be used twice

  • Loading branch information...
1 parent 89610a7 commit b4ec7d11cd83a9cd00e3db02460f6ed9687a4e4e BuzzTroll committed Jun 2, 2010
View
@@ -72,11 +72,12 @@ insert into user_alias_types(name) values ('unix');
create table user_alias(
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id char(36) REFERENCES users_canonical(id) NOT NULL,
- alias_name varchar(256) UNIQUE,
+ alias_name varchar(256),
friendly_name varchar(256),
alias_type INTEGER REFERENCES user_alias_types(id) NOT NULL,
alias_type_data varchar(1024),
- UNIQUE(alias_name, alias_type)
+ UNIQUE(alias_name, alias_type),
+ UNIQUE(friendly_name, alias_type)
);
-- the actual data.
@@ -110,7 +110,7 @@ def __init__(self, data_key, access="r", openIt=True):
self.data_key = data_key
self.blockSize = 1024*512
self.hashValue = None
- self.delete_on_close = False
+ self.delete_on_close = True
self.md5er = hashlib.md5()
if not openIt:
@@ -164,6 +164,9 @@ def set_delete_on_close(self, delete_on_close):
# implement file-like methods
def close(self):
+
+ print "closing the file"
+
hashValue = self.get_md5()
if hashValue != None:
try:
@@ -178,6 +181,7 @@ def close(self):
except:
pycb.log(logging.WARNING, "error closing data object %s %s" % (self.fname, sys.exc_info()[0]), tb=traceback)
if self.delete_on_close:
+ print "deleting the file on close"
self.delete()
@@ -563,7 +563,6 @@ def work(self):
rc = self.grant_public_permissions(self.bucketName, self.objectName)
if not rc:
xml = self.request.content.read()
- dataObj.set_delete_on_close(True)
grants = parse_acl_request(xml)
for g in grants:
pycb.log(logging.INFO, "granting %s to %s" % (g[2], g[0]))
@@ -619,7 +618,12 @@ def endGet(self, dataObj):
self.setHeader(self.request, 'ETag', '"%s"' % (eTag))
+ # now that we have the file set delete on close to false
+ # it will now be safe to deal with dropped connections
+ # without having large files left around
+ dataObj.set_delete_on_close(False)
dataObj.close()
+
self.user.put_object(dataObj, self.bucketName, self.objectName)
self.grant_public_permissions(self.bucketName, self.objectName)
View
@@ -166,6 +166,8 @@ def process_event(self, request):
def allowed_event(self, request, user, requestId, path):
pycb.log(logging.INFO, "Access granted to ID=%s requestId=%s uri=%s" % (user.get_id(), requestId, request.uri))
cbR = self.request_object_factory(request, user, path, requestId)
+
+ request.notifyFinish().addErrback(self.error_connection_dropped, cbR)
cbR.work()
# http events. all do the same thing
@@ -186,6 +188,8 @@ def render_DELETE(self, request):
self.process_event(request)
return server.NOT_DONE_YET
+ def error_connection_dropped(self, cbR):
+ print "Error dropped connection"
class CumulusHTTPChannel(http.HTTPChannel):
@@ -63,17 +63,20 @@ def main_trap(argv=sys.argv[1:]):
if opts.canonical_id == None:
opts.canonical_id = add_user_generate_pw(21)
- auth.create_user(display_name, opts.canonical_id, opts.password, opts)
+ try:
+ auth.create_user(display_name, opts.canonical_id, opts.password, opts)
+ except Exception, ex:
+ raise cbToolsException('USEREXISTS', (display_name), ex)
try:
user_id = auth.get_user_id_by_display(display_name)
except Exception, ex:
- raise cbToolsException('UNKNOWN_USER', [display_name], ex)
+ raise cbToolsException('UNKNOWN_USER', (display_name), ex)
try:
u = auth.get_user(user_id)
except:
- raise cbToolsException('UNKNOWN_USER', [user_id], ex)
+ raise cbToolsException('UNKNOWN_USER', (user_id), ex)
opts.ID = user_id
opts.canonical_id = u.get_canonical_id()
@@ -14,6 +14,8 @@ class cbToolsException(Exception):
rcs['UNKNOWN_USER'] = 1
errors['CMDLINE'] = "poorly formed command line : %s"
rcs['CMDLINE'] = 2
+ errors['USEREXISTS'] = "The user %s already exists."
+ rcs['USEREXISTS'] = 3
def __init__(self, code, fmt_set, ex=None):
self.code = code
@@ -45,7 +45,6 @@ def main_trap(argv=sys.argv[1:]):
except:
raise cbToolsException('CMDLINE', ("The quota must be an integer > 0 or the string UNLIMITED"))
- print q
if q < 1:
raise cbToolsException('CMDLINE', ("The quota must be an integer > 0 or the string UNLIMITED"))

0 comments on commit b4ec7d1

Please sign in to comment.