Skip to content

"Integrity constraint violation" when sharing the same item twice with the same user - #14580

Merged
MorrisJobke merged 3 commits into
masterfrom
issue/13765-duplicate-remote-share
Mar 24, 2015
Merged

MorrisJobke merged 3 commits into
masterfrom
issue/13765-duplicate-remote-share

Conversation

@nickvergessen

Copy link
Copy Markdown
Contributor

The problem is, we try to create the same mount point twice. This PR prevents the SQL error that was triggered previously:

server can not add remote share, An exception occurred while executing '
INSERT INTO `oc_share_external`
    (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
with params
[\"http:\\\/\\\/localhost\\\/ownCloud\\\/Master\\\/\", \"blablub\", \"\", \"\\\/Peace\", \"nickv\", \"user2\", \"\\\/Peace\", \"17a857e51e016141bf57b37e9ad43819\", 0, 88]:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'user2-17a857e51e016141bf57b37e9ad43819' for key 'sh_external_mp'

HOWEVER, this means, that 2 people can NOT share a folder test/ with the same person, until that person accepted/denied one of those shares. The problem is, that the (\d+) solution only considers existing files. [guessing from here on] But until the user accepts the share, the mount point does not exist and therefor the (\d+) is not increased.

This also leads to the assumption, that if the user creates a folder with the same name, or receives a local share with the same name, prior to accepting the share, 🙈 things will happen?!

Unluckily @schiesbn is not available atm, so I don't know who can help here? @PVince81 @DeepDiver1975 @icewind1991 ?

Broken Scenarios

Local folder

  1. Open two windows with 2 users on the same instance
  2. Send a S2S share a folder1 from user1 to user2
  3. Create folder1 as user2 and create a file in it
  4. Refresh the page as user2 so the S2S popup shows up and accept the share
  5. Local file is invisible

Local share

  1. Open two windows with 2 users on the same instance
  2. Send a S2S share a folder1 from user1 to user2
  3. Share a folder2/folder1 from user1 to user2 with a local share
  4. Refresh the page as user2, see the local shared folder1 in the background and the S2S popup in fornt and accept the share
  5. Local share is invisible

Mount point

  1. Open two windows with 2 users on the same instance
  2. Send a S2S share a folder1 from user1 to user2
  3. Mount something as folder1 for user2
  4. Refresh the page as user2 so the S2S popup shows up and accept the share
  5. Mount point is invisible

Mount point

  1. Open two windows with 2 users on the same instance
  2. Send a S2S share a folder1 from user1 to user2
  3. Send a S2S share a folder2/folder1 from user1 to user2
  4. Second share fails

@nickvergessen nickvergessen added this to the 8.1-current milestone Feb 27, 2015

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use connection->executeQuery() right away

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this is only temporary and the problem is something else.

@nickvergessen

Copy link
Copy Markdown
Contributor Author

Tested, and indeed the local share is overwritten by the mountpoint 😿

@nickvergessen

Copy link
Copy Markdown
Contributor Author

Okay, the problem is OC_Helper::buildNotExistingFileNameForView only checks for existance, but does not create the folder/file, in case we need to reserve it for something.

What we can do is, use a unique ID for the mount name, and generate the real mount point name at the time where we actually mount the share (by accepting it)

@nickvergessen
nickvergessen force-pushed the issue/13765-duplicate-remote-share branch from be4601b to 0b54ae5 Compare March 2, 2015 10:08
@nickvergessen nickvergessen changed the title [WIP][DO NOT MERGE] "Integrity constraint violation" when sharing the same item twice with the same user "Integrity constraint violation" when sharing the same item twice with the same user Mar 2, 2015
@nickvergessen

Copy link
Copy Markdown
Contributor Author

I think I fixed it in a good way, would be nice if mount point/sharing guys can have a look, since this is rather urgent/critical.

The broken scenarios from above are also something for the testing list @jnfrmarks

@nickvergessen

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 @karlitschek should backport this :/

@nickvergessen
nickvergessen force-pushed the issue/13765-duplicate-remote-share branch 2 times, most recently from 92d8e60 to 9053fb8 Compare March 2, 2015 11:09

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close cursor somewhere ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There query has a limit = 1, so I don't think its necessary?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or fetchAll() might do too, if I remember well it might automatically close the cursor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how Doctrine or the database works. I wouldn't trust the DB to be clever enough to auto-close cursors (hint: Oracle...)

@PVince81

PVince81 commented Mar 2, 2015

Copy link
Copy Markdown
Contributor

Code makes sense, as discussed.
Can you add/update the matching unit test to check for both existing and non-existing mount point cases ?

@MorrisJobke

Copy link
Copy Markdown
Contributor

@nickvergessen are unit tests possible?

@nickvergessen

Copy link
Copy Markdown
Contributor Author

yes I guess so, however I wanted a view of schiesbn on this (he should be available next week), before testing my skills on writing tests for the sharing mess

@nickvergessen
nickvergessen force-pushed the issue/13765-duplicate-remote-share branch from 9053fb8 to 8bb1215 Compare March 17, 2015 09:32
@MorrisJobke

Copy link
Copy Markdown
Contributor

@schiesbn @nickvergessen Is this the way to go? If yes: it needs unit tests ;)

@schiessle

Copy link
Copy Markdown
Contributor

@MorrisJobke just discussed it with @nickvergessen. He will add the unit tests.

Previously the mount name was checked for uniqueness prior to inserting the
share. This caused problems, when two shares with the same name where done
or folder, mount point, local share with the same name was done, between
sending and accepting of the remote share
@nickvergessen
nickvergessen force-pushed the issue/13765-duplicate-remote-share branch from 8bb1215 to 8ebb198 Compare March 17, 2015 15:55
@nickvergessen

Copy link
Copy Markdown
Contributor Author

Added some basic unit tests for addShare, acceptShare, declineShare, getOpenShares and removeUserShares

@MorrisJobke @schiesbn ready for review again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this method, so I can get all shares in the tests, without having to go through the mount logic.

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 1 new issues, 10 updated code elements

@ghost

ghost commented Mar 17, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/10550/
Test PASSed.

@MorrisJobke

Copy link
Copy Markdown
Contributor

Tested and works 👍

MorrisJobke added a commit that referenced this pull request Mar 24, 2015
…share

"Integrity constraint violation" when sharing the same item twice with the same user
@MorrisJobke
MorrisJobke merged commit 965d97a into master Mar 24, 2015
@MorrisJobke
MorrisJobke deleted the issue/13765-duplicate-remote-share branch March 24, 2015 14:18
@schiessle

Copy link
Copy Markdown
Contributor

Reviewed and tested it together with Morris 👍

@nickvergessen

Copy link
Copy Markdown
Contributor Author

Btw, I just realized on another backport, that we didn't backport this one. I think we should? @schiesbn @MorrisJobke

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants