carrierwave-postgresql-table 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/carrierwave/postgresql_table/version.rb +1 -1
- data/lib/carrierwave/storage/postgresql_table.rb +19 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ef806ccfb8914f80bcbe80cdd3ebd8faa89cd7c
|
4
|
+
data.tar.gz: 0ab0e9e7757bb7c0767aa375ea55dceda7b2ac03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cca0e9d3e00674e05e7c224154d225706653393160210c3ae1bc1920ede30840316aa032aef256cf532b47abd89b9770bb25869baf6073300d1845696fda7c7c
|
7
|
+
data.tar.gz: 1d74a9ee0a82fdda54485fffd8cee3c2aa06f84197861ff2941119216fa5c3fa2395aae706253067f8e80c586d9f263b16d8cba0a76e0f72abb8f56548d13e1c
|
data/.gitignore
CHANGED
@@ -119,11 +119,12 @@ module CarrierWave
|
|
119
119
|
|
120
120
|
def store(new_file)
|
121
121
|
CarrierWaveFile.transaction do
|
122
|
+
connection = CarrierWaveFile.connection
|
123
|
+
raw_connection = connection.raw_connection
|
122
124
|
oid = nil
|
123
125
|
if(new_file.kind_of?(CarrierWave::Storage::PostgresqlTable::File))
|
124
126
|
oid = new_file.copy_to(@path)
|
125
127
|
else
|
126
|
-
raw_connection = CarrierWaveFile.connection.raw_connection
|
127
128
|
file = new_file.to_file
|
128
129
|
|
129
130
|
begin
|
@@ -142,10 +143,20 @@ module CarrierWave
|
|
142
143
|
end
|
143
144
|
|
144
145
|
begin
|
146
|
+
old_oid = @record.pg_largeobject_oid
|
145
147
|
@record.pg_largeobject_oid = oid
|
146
148
|
@record.size = new_file.size
|
147
149
|
@record.content_type = new_file.content_type
|
148
150
|
@record.save
|
151
|
+
|
152
|
+
# Cleanup old, unused largeobject OIDs if we're updating the
|
153
|
+
# record with a new OID reference.
|
154
|
+
if(old_oid && old_oid != oid)
|
155
|
+
old_references = connection.select_value("SELECT COUNT(*) FROM #{CarrierWaveFile.table_name} WHERE pg_largeobject_oid = #{CarrierWaveFile.sanitize(old_oid)}").to_i
|
156
|
+
if(old_references == 0)
|
157
|
+
raw_connection.lo_unlink(old_oid)
|
158
|
+
end
|
159
|
+
end
|
149
160
|
rescue ::ActiveRecord::RecordNotUnique
|
150
161
|
@record = CarrierWaveFile.find_or_initialize_by(:path => @path)
|
151
162
|
retry
|
@@ -174,7 +185,13 @@ module CarrierWave
|
|
174
185
|
end
|
175
186
|
|
176
187
|
def move_to(new_path)
|
177
|
-
|
188
|
+
CarrierWaveFile.transaction do
|
189
|
+
# Remove any existing files at the current path.
|
190
|
+
CarrierWaveFile.delete_all_files("path = #{CarrierWaveFile.sanitize(new_path)} AND id != #{CarrierWaveFile.sanitize(@record.id)}")
|
191
|
+
|
192
|
+
# Change the current record's path to the new path.
|
193
|
+
@record.update_attribute(:path, new_path)
|
194
|
+
end
|
178
195
|
end
|
179
196
|
|
180
197
|
def delete
|